Need help to this program

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

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

	
	cout << "Enter number 1 ";
	cin >> num1;
	cout << "Enter number 2 ";
	cin >> num2;

	
	cout << "Choose arithmetic process " << endl;
	cout << " A for add ";
	cout << " S for subtract ";
	cout << " M for multiply ";
	cout << " D for divide ";
	cin >> input;
	switch (input)
	{
	case 'A': case 'a':
		sum = num1 + num2;
		cout << "The sum is " << sum << endl;
		break;
	case 'S': case 's':
		difference = num1 - num2;
		cout << " The difference is " << difference << endl;
		break;
	case 'M': case 'm':
		product = num1 * num2;
		cout << " The product is " <<product << endl;
		break;
	case 'D': case 'd':
		quotient = num1 / num2;
		cout << "The quotient is " << quotient << endl;
		break;

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


I need help on how to code it that if you pick 'Y'/'y' you will perform the same operation....can someone help?
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
#include <iostream>
using namespace std;

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

	
	cout << "Enter number 1 ";
	cin >> num1;
	cout << "Enter number 2 ";
	cin >> num2;

	
	cout << "Choose arithmetic process " << endl;
	cout << " A for add ";
	cout << " S for subtract ";
	cout << " M for multiply ";
	cout << " D for divide ";
	cin >> input;
	switch (input)
	{
	case 'A': case 'a':
		sum = num1 + num2;
		cout << "The sum is " << sum << endl;
		break;
	case 'S': case 's':
		difference = num1 - num2;
		cout << " The difference is " << difference << endl;
		break;
	case 'M': case 'm':
		product = num1 * num2;
		cout << " The product is " <<product << endl;
		break;
	case 'D': case 'd':
		quotient = num1 / num2;
		cout << "The quotient is " << quotient << endl;
		break;

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

There you go. :) All you needed to do was change the do-while loops condition to n != 'n' && n != 'N'. That's just saying, run the loop while n is not equal to 'n' and n is not equal to 'N'. If it's anything other than that, the loop will 'loop' back to the top.
Last edited on
tnx ^^
Is this what you are looking for? http://www.cplusplus.com/reference/clibrary/cctype/toupper/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cctype>

// ...

    do 
    {
        // ...

        cout << " try again? (y/n)" << endl;
        cin >> n;
        
        toupper(n);
    }
    while (n == 'Y');

// ... 


Edit:
Wow, how do I keep missing posts submitted before me? Oh well, I misinterpreted your question, glad you got the answer though!
Last edited on
Topic archived. No new replies allowed.