Program Not Exiting

Write your question here.
Why is the program not exiting? See case 0: in switch, line 46.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
*	Chapter 21 Problem 1
*
*	Write a program that contains the functions add, subtract,
*	multiply, and divide.  Each of these functions should take
*	two integers and return the results of the operation. Create
*	a small calculator that uses these functions. Put the function
*	declarations into a header file, but include the source code
*	for these functions in your source code.
*
*/

#include <iostream>
#include "Calculator.h"

using namespace std;



int main()
{
	// Declare and initialize variables
	int x_value = 0;
	int y_value = 0;
	int selection = 0;
	bool repeat = true;
	
	while (repeat == true)
	{
		cout << "Menu: " << endl;
		cout << '\t' << "0. Exit" << endl;
		cout << '\t' << "1. Add" << endl;
		cout << '\t' << "2. Subtract" << endl;
		cout << '\t' << "3. Multiply" << endl;
		cout << '\t' << "4. Divide" << endl;
		cout << "Please select a number from the Menu: ";
		cin >> selection;

		cout << endl << "Please provide me with integer variable x: ";
		cin >> x_value;
		cout << "Please provide me with integer variable y: ";
		cin >> y_value;

		switch (selection)
		{
		case 0:
			repeat = false;
			break;
		case 1:
			cout << "x + y = " << AddFunction(x_value, y_value) << endl << endl;
			break;
		case 2:
			cout << "x - y = " << SubtractFunction(x_value, y_value) << endl << endl;
			break;
		case 3:
			cout << "x * y = " << MultiplyFunction(x_value, y_value) << endl << endl;
			break;
		case 4:
			cout << "x / y = " << DivideFunction(x_value, y_value) << endl << endl;
			break;
		}
	}
}

// Function Definitions
int AddFunction(int x, int y)
{
	int result = 0;
	return result = x + y;
}

int SubtractFunction(int x, int y)
{
	int result = 0;
	return result = x - y;
}

int MultiplyFunction(int x, int y)
{
	int result = 0;
	return result = x * y;
}

int DivideFunction(int x, int y)
{
	int result = 0;
	return result = x / y;
}
.
It does exit when i tried it. Of course the execution has to make its way as far as the closing brace at line 62, when it will go back to the top of the while loop, test the value of repeat, and then terminate.

If you don't want any of the code from line 39 to 42 to execute when the user selected option 0, you would need to change the logic, for example by enclosing that part of the code in an if statement
Chervil,

Thank you I added the if statement, and it works the way I though it was suppose to and not go through lines 39 to 42.
Topic archived. No new replies allowed.