Getting program to exit with user input

I have to exit the program when the user inputs e, but for some reason it continues. I am just not seeing what the problem is.

Here is the code for the functions I am using in main and the function that is called to get the user to input which menu item they want.

I cannot use break or return 0, it has to be only when the user chooses e.

Any ideas??

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
do {
     getChoice(choice);
     getNumbers(beginBalance, rate, years);
     getCalculations();
     getResults(beginBalance, rate, years, calcYInt, totalYAmt, calcMInt, totalMAmt, calcWInt, totalWAmt, calcDInt,
             totalDAmt);
     } while (choice != 'E');

     cin.get();
     return 0;
}

void getChoice(char& choice)
{
     cout << "Compare Annual Compounding to:" << endl;
     cout << setw(3) << " " << "M - Monthly Compounding" << endl;
     cout << setw(3) << " " << "W - Weekly Compounding" << endl;
     cout << setw(3) << " " << "D - Daily Compounding" << endl;
     cout << setw(3) << " " << "E - Exit Program" << endl << endl;
     cout << "Enter Choice from menu above: ";
     cin >> choice;
     choice = toupper(choice);
     cout << endl;

     switch (choice) {               //start switch plan
     case 'M':
          cout << "M - Monthly Compounding" << endl << endl;
          break;

     case 'W':
          cout << "W - Weekly Compounding" << endl << endl;
          break;

     case 'D':
          cout << "D - Daily Compounding" << endl << endl;
          break;

     case 'E':
          cout << "E - Exit Program" << endl << endl;
          break;

     default:
          cout << "Please enter a valid menu choice from above: ";
          cin >> choice;
          break;
     }         //end switch plan

}
Last edited on
1
2
3
case 'E':
          cout << "E - Exit Program" << endl << endl;
          exit(0);
Topic archived. No new replies allowed.