Need help again...^^...

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
#include <iostream>
using namespace std;

int main()
{
	char n;
	do
	{
	int input;
	int num1, num2, sum, difference, product, quotient = 0;

	cout << "Choose arithmetic process " << endl;
	cout << " 1. Multiplication " << endl;
	cout << " 2. Division " << endl;
	cout << " 3. Addition " << endl;
	cout << " 4. Subtraction " << endl;
	cout << " 5. Exit " << endl;
	cin >> input;
	if(input <= 4)
	{
	cout << "Enter two number " << endl;
	cin >> num1 >> num2;
	}
	switch (input)
	{
	case 1:
		product = num1 * num2;
		cout << "The product is " << product << endl;
		break;
	case 2:
		quotient = num1 / num2;
		cout << " The quotient is " << quotient << endl;
		break;
	case 3:
		sum = num1 + num2;
		cout << " The sum is " << sum << endl;
		break;
	case 4:
		difference = num1 - num2;
		cout << "The difference is " << difference << endl;
		break;
	case 5:
		cout << " you choose to exit " << endl;
		break;

	}
	cout << " try again? (y/n)" << endl;
	cin >> n;
	} while(n != 'n' && n != 'N');
	cout << endl;
return 0;
}


1st problem: I need the program to repeat the operation it did if you select 'Y'.
example:
you choose to multiply and you finished.
try again?(y/n)
y
and when you select y you will be prompted by the program to enter 2 numbers and multiply the two number you put again.

2nd problem: if you select '5' the program must exit.
and also a little reminder, if you select 'n' it's just like that it will go to the start and ask you to choose arithmetic process.

So anyone, will ya help? ^^
create ()s to get value from the user and call it if choice is y and then go to the beginning of the loop. In case 5, use return 0 instead of break to exit.
tnx for the 2nd problem it's fixed but the 1st one I didn't get it...can you put it in the code where will I change it...sorry if it's a hassle...
Change case 5 to this.
1
2
3
4
case 5:
		cout << " you choose to exit " << endl;
		n = 'n';
                break;

Just add another loop to fix the first problem. Either that, or remove that bit of code from the do-while loop. You should also think about re-writing the calculator to allow the user to input something like (number) (operator) (number). Doing that would defiantly make your calculator more user friendly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	char n;
        int input;
        cout << "Choose arithmetic process " << endl;
	cout << " 1. Multiplication " << endl;
	cout << " 2. Division " << endl;
	cout << " 3. Addition " << endl;
	cout << " 4. Subtraction " << endl;
	cout << " 5. Exit " << endl;
	cin >> input;
	do
	{
            // ...
	} while(n != 'n' && n != 'N');
	cout << endl;
        return 0;
}

You should refrain from asking questions like this and try to solve them yourself. It's really not good (especially when learning) to ask so many question because you might begin to rely on others.
Last edited on
tnx for the explanation...and don't worry I don't plan to rely on others it's just that I don't know where to change or fix the program...sorry if I dissapoint you...^^
Topic archived. No new replies allowed.