I am having trouble making this menu, I followed some instructions online but I can't seem to get it to loop back to the menu after I am done with a menu selection. Please Help!

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main ()
{
    int choice;
    int loop=1;
    
    while(loop==1)
    {
          system ("CLS");
          cout << "****Patrick's Menu of Things****\n\n"
               << "1. Pythagorean Theorem Calculator v1.2\n"
               << "2. Area of a Triangle Calculator\n"
               << "3. Distance Calculator(XY Plane)\n"
               << "4. Another Thing\n"
               << "5. A Fifth Thing\n"
               << "6. **Exit**\n\n";
          cin >> choice;
          
          switch(choice)
          {
                 case 1:
                       system ("CLS");
                       cout << "PYTHAGOREAN THEOREM CALCULATOR" << endl;
                       cout << "ENTER BOTH LEGS OF THE TRIANGLE" << endl;
    
                       int a, b;
                       float C;
                       cout << "LEG 1:";
                       cin >> a;
                       cout << "LEG 2:";
                       cin >> b;
                       C = sqrt ( ( a * a ) + ( b * b ) );
                       cout << "THE HYPONTENUSE IS:" << C << endl;
                       system ("PAUSE");
                      
                 case 2:
                      system ("CLS");
                      cout << "TRIANGLE AREA CALCULATOR" << endl;
                      cout << "ENTER BASE AND HEIGHT OF TRIANGLE:" << endl;
   
                      int h, c;
                      cout << "BASE:";
                      cin >> b;
                      cout << "HEIGHT:";
                      cin >> h;
                      cout << "PROCESSING!" << endl;
   
                      c = ( b * h ) / 2;
                      cout << "THE AREA OF THE TRIANGLE IS:" << c << endl;
   
                      system("PAUSE");
                 
                 case 3:
                        system ("CLS");
                        cout << "DISTANCE FORMULA CALCULATOR" << endl;
                        cout << "ENTER THE TWO COORDINATES HERE" << endl;
    
                        float X, Y, x, y, Distance;
    
                        cout << "ENTER FIRST COORDINATE(LEAVE A SPACE BETWEEN X AND Y):";
                        cin >> X >> Y;
    
                        cout << "ENTER SECOND COORDINATE(LEABE A SPACE BETWEEN X AND Y):";
                        cin >> x >> y;
    
                        Distance = sqrt(pow((X - x),2) + pow((Y - y),2));
    
                        cout << "THE DISTANCE IS:" << Distance << endl;
    
                        system("PAUSE");
                  
                   case 4:  
                        system ("CLS");
                        cout << "You Suck\n";
                        system ("PAUSE");
                        
                   case 5:
                        system ("CLS");
                        cout << "You Suck More\n";
                        system ("PAUSE");
                   
                   case 6:
                        if(choice==6)
                        {
                           exit(0);
                        }
                   }
                 }
}

You need a break after each case otherwise it will continue through the cases.


So a case should look like:

case 1:
system ("CLS");
cout << "PYTHAGOREAN THEOREM CALCULATOR" << endl;
cout << "ENTER BOTH LEGS OF THE TRIANGLE" << endl;
int a, b;
float C;
cout << "LEG 1:";
cin >> a;
cout << "LEG 2:";
cin >> b;
C = sqrt ( ( a * a ) + ( b * b ) );
cout << "THE HYPONTENUSE IS:" << C << endl;
system ("PAUSE");
break;

Edited 5 Years Ago by Phinisher: n/a

You need a break after each case otherwise it will continue through the cases.


So a case should look like:

case 1:
system ("CLS");
cout << "PYTHAGOREAN THEOREM CALCULATOR" << endl;
cout << "ENTER BOTH LEGS OF THE TRIANGLE" << endl;
int a, b;
float C;
cout << "LEG 1:";
cin >> a;
cout << "LEG 2:";
cin >> b;
C = sqrt ( ( a * a ) + ( b * b ) );
cout << "THE HYPONTENUSE IS:" << C << endl;
system ("PAUSE");
break;

Thanks so much!

This question has already been answered. Start a new discussion instead.