### Continue Until Choosing to Exit

Hello, Im having trouble getting the program to continue running until the user chooses to exit. I have managed to create an exit statement, however it doesn't give me the option to continue after the program gives you an answer.
this is what I have so far,

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104`` `````` #include #include using namespace std; void Values(double &num1, double &num2) { cout << "Please enter two numbers to calculate; " << setprecision(5) << "\nNumber 1 " <> num1; cout <> num2; } void Addition(double &num1, double &num2, double &Result) { Result = num1 + num2; } void Subtraction(double &num1, double &num2, double &Result) { Result = num1 - num2; } void Multiplication(double &num1, double &num2, double &Result) { Result= num1 * num2; } void Division(double &num1, double &num2, double &Result) { if(num2 != 0) { setprecision(5); Result = num1 / num2; } else cout << "Please enter a number other than 0 as denominator"<> choice; switch(choice) // Switch function allows user to choose the calculation to execute { case 'A': case 'a': Addition(num1, num2, Result); break; case 'S': case 's': Subtraction(num1, num2, Result); break; case 'M': case 'm': Multiplication(num1, num2, Result); break; case 'D': case 'd': Division(num1, num2, Result); break; default: case 'E': case'e': cout << "E - Exit Program" << endl << endl; exit(0); cout << "Please enter a valid menu choice from above: "; cin >> choice; break; } { cout << "result is " << Result <
The general way is to use a do-while or while loop. For example

while ( true )
{
switch(choice) // Switch function allows user to choose the calculation to execute
{
case 'A':
case 'a':
break;
case 'S':
case 's':
Subtraction(num1, num2, Result);
break;
case 'M':
case 'm':
Multiplication(num1, num2, Result);
break;
case 'D':
case 'd':
Division(num1, num2, Result);
break;
default:
case 'E':
case'e':
cout << "E - Exit Program" << endl << endl;
exit(0);

cin >> choice;
break;

}

Last edited on
Thanks, I know I'm suppose to use the do-while, but Im not sure how to add it since i have this,
 ``123456`` ``````if(num2 != 0) { setprecision(5); Result = num1 / num2; } else``````
Topic archived. No new replies allowed.