#include <iostream>
usingnamespace 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.
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.
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.
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.
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...^^