Need help with menu program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • namcintosh
    New Member
    • Apr 2007
    • 67

    Need help with menu program

    Hello, everyone.

    Well, let me cut to the chase and explain my problem.

    I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight on a given planet. It first asks for the user's weight, asks them for a choice. If they choose choices 1 though 9, the user's weight will be calculated on whatever choice they picked (for example, if the user inputs 150 as their weight and choose choice #2 for Venus, then the user's weight on Venus would be 135 pounds. However, I am running into some problems.

    When I compile the program, the output does not come out as I expect.
    The program and the results are listed below:

    Program:
    // This menu-driven program uses an if/else statement to calculate
    // the user's weight on a given planet. It also inserts a loop.

    #include <iostream>
    #include <iomanip> //Needed for the setprecison command
    #include <conio> //Needed to show black output screen
    using namespace std;

    int main()
    {
    int choice;
    double weight1, weight2;


    // Displays the menu choices on the screen.
    cout << "\t\tPlanet Menu\n\n";
    cout << "1. Mercury\n";
    cout << "2. Venus\n";
    cout << "3. Earth\n";
    cout << "4. Mars\n";
    cout << "5. Jupiter\n";
    cout << "6. Saturn\n";
    cout << "7. Uranus\n";
    cout << "8. Neptune\n";
    cout << "9. Pluto\n";
    cout << "99. Exit\n\n";

    cout << "Enter your weight: ";
    cin >> weight1;

    while (choice !=99)

    if (choice == 1)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.40;
    cout << "You will weight" << weight2 << "on Mercury." <<endl;
    }
    else if (choice == 2)
    {
    cout << "Please make a selection. ";
    cin >> choice;
    weight2 = weight1 * 0.90;
    cout << "You will weight" << weight2 << "on Venus." <<endl;
    }
    else if (choice == 3)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.00;
    cout << "You will weight" << weight2 << "on Earth." <<endl;
    }
    else if (choice == 4)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.40;
    cout << "You will weight" << weight2 << "on Mars." <<endl;
    }
    else if (choice == 5)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 2.50;
    cout << "You will weight" << weight2 << "on Jupiter . " <<endl;
    }
    else if (choice == 6)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.10;
    cout << "You will weight" << weight2 << "on Saturn." <<endl;
    }
    else if (choice == 7)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.80;
    cout << "You will weight" << weight2 << "on Uranus." <<endl;
    }
    else if (choice == 8)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.2;
    cout << "You will weight" << weight2 << "on Neptune. " <<endl;

    }
    else if (choice == 9)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.01;
    cout << "You will weight" << weight2 << "on Pluto. " <<endl;
    }
    //Outputs the following message when user enters number other
    //than 1 through 9 or 99 on the screen.
    else if (choice !=99)
    {
    cout << "The valid choices are 1 through 9 or 99 to exit.\n";
    cout << "Run the program again and select one of those.\n";
    }

    getch();
    return 0;
    }

    Output Line:
    Planet Menu

    1. Mercury
    2. Venus
    3. Earth
    4. Mars
    5. Jupiter
    6. Saturn
    7. Uranus
    8. Neptune
    9. Pluto
    99. Exit

    Enter your weight: 150
    Please make a selection 2
    You will weight60on Mercury.
    Please make a selection. 2
    You will weight135on Venus.
    Please make a selection. 99
    You will weight135on Venus.


    Do you see the problem? No matter what choice I key in for the first choice, it always calculates for Mercury. Then, when I put that choice in again, it calculates the correct choice. Also, the choice 99 should exit, not do a calculation. (Note: The errors are in bold.) And, when I key in a value that is not one of the choices, instead of just showing "The valid choices are 1 through 9 or 99 to exit. Run the program again and select one of those," all I get is an infinite loop with this statement.
    Could there be something wrong with my loops???
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by namcintosh
    Hello, everyone.

    Well, let me cut to the chase and explain my problem.

    I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight on a given planet. It first asks for the user's weight, asks them for a choice. If they choose choices 1 though 9, the user's weight will be calculated on whatever choice they picked (for example, if the user inputs 150 as their weight and choose choice #2 for Venus, then the user's weight on Venus would be 135 pounds. However, I am running into some problems.

    When I compile the program, the output does not come out as I expect.
    The program and the results are listed below:

    Program:
    // This menu-driven program uses an if/else statement to calculate
    // the user's weight on a given planet. It also inserts a loop.

    #include <iostream>
    #include <iomanip> //Needed for the setprecison command
    #include <conio> //Needed to show black output screen
    using namespace std;

    int main()
    {
    int choice;
    double weight1, weight2;


    // Displays the menu choices on the screen.
    cout << "\t\tPlanet Menu\n\n";
    cout << "1. Mercury\n";
    cout << "2. Venus\n";
    cout << "3. Earth\n";
    cout << "4. Mars\n";
    cout << "5. Jupiter\n";
    cout << "6. Saturn\n";
    cout << "7. Uranus\n";
    cout << "8. Neptune\n";
    cout << "9. Pluto\n";
    cout << "99. Exit\n\n";

    cout << "Enter your weight: ";
    cin >> weight1;

    while (choice !=99)

    if (choice == 1)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.40;
    cout << "You will weight" << weight2 << "on Mercury." <<endl;
    }
    else if (choice == 2)
    {
    cout << "Please make a selection. ";
    cin >> choice;
    weight2 = weight1 * 0.90;
    cout << "You will weight" << weight2 << "on Venus." <<endl;
    }
    else if (choice == 3)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.00;
    cout << "You will weight" << weight2 << "on Earth." <<endl;
    }
    else if (choice == 4)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.40;
    cout << "You will weight" << weight2 << "on Mars." <<endl;
    }
    else if (choice == 5)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 2.50;
    cout << "You will weight" << weight2 << "on Jupiter . " <<endl;
    }
    else if (choice == 6)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.10;
    cout << "You will weight" << weight2 << "on Saturn." <<endl;
    }
    else if (choice == 7)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.80;
    cout << "You will weight" << weight2 << "on Uranus." <<endl;
    }
    else if (choice == 8)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 1.2;
    cout << "You will weight" << weight2 << "on Neptune. " <<endl;

    }
    else if (choice == 9)
    {
    cout << "Please make a selection ";
    cin >> choice;
    weight2 = weight1 * 0.01;
    cout << "You will weight" << weight2 << "on Pluto. " <<endl;
    }
    //Outputs the following message when user enters number other
    //than 1 through 9 or 99 on the screen.
    else if (choice !=99)
    {
    cout << "The valid choices are 1 through 9 or 99 to exit.\n";
    cout << "Run the program again and select one of those.\n";
    }

    getch();
    return 0;
    }

    Output Line:
    Planet Menu

    1. Mercury
    2. Venus
    3. Earth
    4. Mars
    5. Jupiter
    6. Saturn
    7. Uranus
    8. Neptune
    9. Pluto
    99. Exit

    Enter your weight: 150
    Please make a selection 2
    You will weight60on Mercury.
    Please make a selection. 2
    You will weight135on Venus.
    Please make a selection. 99
    You will weight135on Venus.


    Do you see the problem? No matter what choice I key in for the first choice, it always calculates for Mercury. Then, when I put that choice in again, it calculates the correct choice. Also, the choice 99 should exit, not do a calculation. (Note: The errors are in bold.) And, when I key in a value that is not one of the choices, instead of just showing "The valid choices are 1 through 9 or 99 to exit. Run the program again and select one of those," all I get is an infinite loop with this statement.
    Could there be something wrong with my loops???
    Hello, I don't really see your braces for your while loop. Is that a typo?
    Second, the first time you run the loop the program doesn't know what choice is since you ask the user for the values in the if statements. You should ask for choice at the beggining of the loop and then check what is it is with the ifs. Hope that helps.

    Comment

    • namcintosh
      New Member
      • Apr 2007
      • 67

      #3
      Originally posted by ilikepython
      Hello, I don't really see your braces for your while loop. Is that a typo?
      Second, the first time you run the loop the program doesn't know what choice is since you ask the user for the values in the if statements. You should ask for choice at the beggining of the loop and then check what is it is with the ifs. Hope that helps.
      No, that's not a typo. Where should I put the braces for my while loop? Also, are youu saying that I should ask for the choice after I typed in "Please enter your weight."

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by namcintosh
        No, that's not a typo. Where should I put the braces for my while loop? Also, are youu saying that I should ask for the choice after I typed in "Please enter your weight."
        Hi, Your braces for the while loop should be one right after the while statement and one after the last if block. That way it will execute until the user enters 99.
        Also the "cin >> choice;" line should be at the beginning of the while loop like this:
        Code:
        while (choice != 99)
            {
                cin >> choice;
        
        /* calculate weight
            ................. */
            }                       //close while loop
        Does that help?

        Comment

        • ilikepython
          Recognized Expert Contributor
          • Feb 2007
          • 844

          #5
          Oh and also, I'm not exactly sure but there's probably a better way to get the calculated weight depending on the choice instead of all those if statements.

          Comment

          • namcintosh
            New Member
            • Apr 2007
            • 67

            #6
            Originally posted by ilikepython
            Oh and also, I'm not exactly sure but there's probably a better way to get the calculated weight depending on the choice instead of all those if statements.
            Well, my homework required that I use the if/else-if loop for this program; it's a new section that I am on.

            Also, I tried that, and this is what happened:

            cout << "Enter your weight: ";
            cin >> weight1;

            while (choice !=99)
            {
            cin >> choice;
            }

            if (choice == 1)
            {
            cout << "Please make a selection ";
            cin >> choice;
            weight2 = weight1 * 0.40;
            cout << "You will weight" << weight2 << "on Mercury." <<endl;
            }
            Planet Menu

            1. Mercury
            2. Venus
            3. Earth
            4. Mars
            5. Jupiter
            6. Saturn
            7. Uranus
            8. Neptune
            9. Pluto
            99. Exit

            Enter your weight: 185
            9

            What am I doing wrong.

            Comment

            • ilikepython
              Recognized Expert Contributor
              • Feb 2007
              • 844

              #7
              Originally posted by namcintosh
              Well, my homework required that I use the if/else-if loop for this program; it's a new section that I am on.

              Also, I tried that, and this is what happened:

              cout << "Enter your weight: ";
              cin >> weight1;

              while (choice !=99)
              {
              cin >> choice;
              }

              if (choice == 1)
              {
              cout << "Please make a selection ";
              cin >> choice;
              weight2 = weight1 * 0.40;
              cout << "You will weight" << weight2 << "on Mercury." <<endl;
              }
              Planet Menu

              1. Mercury
              2. Venus
              3. Earth
              4. Mars
              5. Jupiter
              6. Saturn
              7. Uranus
              8. Neptune
              9. Pluto
              99. Exit

              Enter your weight: 185
              9

              What am I doing wrong.
              You put the closing while brace after the "cin" line. That i means it will repaetedly ask for choice until you enter 99. You don't want that. Try putting it at the end of all the calculations so the it can loop correctly like this:
              Code:
              while (choice is not 99)
                  {                                         // begin brace
                      ask for choice
                      calculate weight here
                  }                                           // end brace after everything is done
              so once it reaches the end brace it "loops" back up to the begin brace.

              Does that clarify things?

              Comment

              • namcintosh
                New Member
                • Apr 2007
                • 67

                #8
                Originally posted by ilikepython
                You put the closing while brace after the "cin" line. That i means it will repaetedly ask for choice until you enter 99. You don't want that. Try putting it at the end of all the calculations so the it can loop correctly like this:
                Code:
                while (choice is not 99)
                    {                                         // begin brace
                        ask for choice
                        calculate weight here
                    }                                           // end brace after everything is done
                so once it reaches the end brace it "loops" back up to the begin brace.

                Does that clarify things?
                Pardon me, if I seem like a dummy; but I am really new at this.
                Can you please insert in the program where exactly does that statement go???
                Here is the program again:
                cout << "Enter your weight: ";
                cin >> weight1;

                while (choice !=99)
                {
                cin >> choice;
                }

                if (choice == 1)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 0.40;
                cout << "You will weight" << weight2 << "on Mercury." <<endl;
                }
                else if (choice == 2)
                {
                cout << "Please make a selection. ";
                cin >> choice;
                weight2 = weight1 * 0.90;
                cout << "You will weight" << weight2 << "on Venus." <<endl;
                }
                else if (choice == 3)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 1.00;
                cout << "You will weight" << weight2 << "on Earth." <<endl;
                }
                else if (choice == 4)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 0.40;
                cout << "You will weight" << weight2 << "on Mars." <<endl;
                }
                else if (choice == 5)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 2.50;
                cout << "You will weight" << weight2 << "on Jupiter . " <<endl;
                }
                else if (choice == 6)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 1.10;
                cout << "You will weight" << weight2 << "on Saturn." <<endl;
                }
                else if (choice == 7)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 0.80;
                cout << "You will weight" << weight2 << "on Uranus." <<endl;
                }
                else if (choice == 8)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 1.2;
                cout << "You will weight" << weight2 << "on Neptune. " <<endl;

                }
                else if (choice == 9)
                {
                cout << "Please make a selection ";
                cin >> choice;
                weight2 = weight1 * 0.01;
                cout << "You will weight" << weight2 << "on Pluto. " <<endl;
                }
                //Outputs the following message when user enters number other
                //than 1 through 9 or 99 on the screen.
                else if (choice !=99)
                {
                cout << "The valid choices are 1 through 9 or 99 to exit.\n";
                cout << "Run the program again and select one of those.\n";
                }

                getch();
                return 0;
                }

                Comment

                • ilikepython
                  Recognized Expert Contributor
                  • Feb 2007
                  • 844

                  #9
                  Originally posted by namcintosh
                  Pardon me, if I seem like a dummy; but I am really new at this.
                  Can you please insert in the program where exactly does that statement go???
                  Here is the program again:
                  Code:
                   cout << "Enter your weight: ";
                  	cin  >> weight1;
                  
                                  while (choice !=99)
                                  [B]{[/B]
                                     cin >> choice;
                  
                                  if (choice == 1)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 0.40;
                  		cout << "You will weight" << weight2 << "on Mercury." <<endl;
                        	        }
                                  else if (choice == 2)
                  		{
                  		cout << "Please make a selection. ";
                  		cin  >> choice;
                  		weight2 = weight1 * 0.90;
                  		cout << "You will weight" << weight2 << "on Venus." <<endl;
                        	        }
                                  else if (choice == 3)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 1.00;
                                  cout << "You will weight" << weight2 << "on Earth." <<endl;
                  		}
                                  else if (choice == 4)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 0.40;
                  		cout << "You will weight" << weight2 << "on Mars." <<endl;
                  		}
                                  else if (choice == 5)
                  		{
                  		cout <<  "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 2.50;
                                  cout << "You will weight" << weight2  << "on Jupiter . " <<endl;
                                  }
                                  else if (choice == 6)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 1.10;
                                  cout << "You will weight" << weight2 << "on Saturn." <<endl;
                                  }
                                  else if (choice == 7)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 0.80;
                                  cout << "You will weight" << weight2 << "on Uranus." <<endl;
                        	        }
                                  else if (choice == 8)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 1.2;
                                  cout << "You will weight" << weight2 << "on Neptune. " <<endl;
                  
                        	        }
                                  else if (choice == 9)
                  		{
                  		cout << "Please make a selection ";
                  		cin  >> choice;
                  		weight2 = weight1 * 0.01;
                                  cout << "You will weight" << weight2 << "on Pluto. "  <<endl;
                                  }
                                  //Outputs the following message when user enters number other
                                  //than 1 through 9 or 99 on the screen.
                  	        else if (choice !=99)
                                  {
                                  cout << "The valid choices are 1 through 9 or 99 to exit.\n";
                                  cout << "Run the program again and select one of those.\n";
                                  }
                                  [B]}[/B]
                          getch();
                  	return 0;
                  }
                  That's Ok.
                  I edited it. Notice the position of the while braces: they're in bold.
                  If you need more help just ask.

                  Comment

                  • namcintosh
                    New Member
                    • Apr 2007
                    • 67

                    #10
                    Originally posted by ilikepython
                    That's Ok.
                    I edited it. Notice the position of the while braces: they're in bold.
                    If you need more help just ask.

                    Well, I got half of the problem right, thanks to you. :-)

                    However, I am still running into a problem.
                    Here is my output:
                    Output 1
                    Planet Menu

                    1. Mercury
                    2. Venus
                    3. Earth
                    4. Mars
                    5. Jupiter
                    6. Saturn
                    7. Uranus
                    8. Neptune
                    9. Pluto
                    99. Exit

                    Enter your weight: 185
                    5
                    Please make a selection 5
                    You will weight462.5on Jupiter .
                    6
                    Please make a selection 6
                    You will weight203.5on Saturn.

                    As you see, it first asks me for my weight. Because I have the cin >> choice line, it waits for me to enter a choice. then, once I enter a choice, it then asks me to make a selection. But, when I deleted the cin >> choice, this is the problem that I ran into:

                    Output 2:
                    Planet Menu

                    1. Mercury
                    2. Venus
                    3. Earth
                    4. Mars
                    5. Jupiter
                    6. Saturn
                    7. Uranus
                    8. Neptune
                    9. Pluto
                    99. Exit

                    Enter your weight: 185
                    Please make a selection 1
                    You will weight74on Mercury.
                    Please make a selection 2
                    You will weight74on Mercury.
                    Please make a selection. 2
                    You will weight166.5on Venus.
                    Please make a selection. 99
                    You will weight166.5on Venus.

                    Also, when I enter an invalid amout, it shows the infinite loop again. What do I do. The first input is right (it makes the right calculations and executes correctly), but how can I make it stop asking the user for the choice twice and make it ask for it once instead. Do you have C++ on your computer? Maybe you can copy and paste the program and you will see what I mean.

                    Thanks!!!

                    Comment

                    • ilikepython
                      Recognized Expert Contributor
                      • Feb 2007
                      • 844

                      #11
                      Originally posted by namcintosh
                      Well, I got half of the problem right, thanks to you. :-)

                      However, I am still running into a problem.
                      Here is my output:
                      Output 1
                      Planet Menu

                      1. Mercury
                      2. Venus
                      3. Earth
                      4. Mars
                      5. Jupiter
                      6. Saturn
                      7. Uranus
                      8. Neptune
                      9. Pluto
                      99. Exit

                      Enter your weight: 185
                      5
                      Please make a selection 5
                      You will weight462.5on Jupiter .
                      6
                      Please make a selection 6
                      You will weight203.5on Saturn.

                      As you see, it first asks me for my weight. Because I have the cin >> choice line, it waits for me to enter a choice. then, once I enter a choice, it then asks me to make a selection. But, when I deleted the cin >> choice, this is the problem that I ran into:

                      Output 2:
                      Planet Menu

                      1. Mercury
                      2. Venus
                      3. Earth
                      4. Mars
                      5. Jupiter
                      6. Saturn
                      7. Uranus
                      8. Neptune
                      9. Pluto
                      99. Exit

                      Enter your weight: 185
                      Please make a selection 1
                      You will weight74on Mercury.
                      Please make a selection 2
                      You will weight74on Mercury.
                      Please make a selection. 2
                      You will weight166.5on Venus.
                      Please make a selection. 99
                      You will weight166.5on Venus.

                      Also, when I enter an invalid amout, it shows the infinite loop again. What do I do. The first input is right (it makes the right calculations and executes correctly), but how can I make it stop asking the user for the choice twice and make it ask for it once instead. Do you have C++ on your computer? Maybe you can copy and paste the program and you will see what I mean.

                      Thanks!!!
                      Ok, since you already asked the user for choice at the beginning of the while loop you don't need to ask again. So, in your if blocks, delete the "cin >> choice" line and the "cout << "Please enter your selection" << endl;" line.

                      Code:
                      if (choice == 1)
                      {
                      cout << "Please make a selection ";
                      cin >> choice;
                      weight2 = weight1 * 0.40;
                      cout << "You will weight" << weight2 << "on Mercury." <<endl;
                      }
                      should become
                      Code:
                      if (choice == 1)
                      {
                      weight2 = weight1 * 0.40;
                      cout << "You will weight" << weight2 << "on Mercury." <<endl;
                      }
                      That should do it

                      Comment

                      • namcintosh
                        New Member
                        • Apr 2007
                        • 67

                        #12
                        Originally posted by ilikepython
                        Ok, since you already asked the user for choice at the beginning of the while loop you don't need to ask again. So, in your if blocks, delete the "cin >> choice" line and the "cout << "Please enter your selection" << endl;" line.

                        Code:
                        if (choice == 1)
                        {
                        cout << "Please make a selection ";
                        cin >> choice;
                        weight2 = weight1 * 0.40;
                        cout << "You will weight" << weight2 << "on Mercury." <<endl;
                        }
                        should become
                        Code:
                        if (choice == 1)
                        {
                        weight2 = weight1 * 0.40;
                        cout << "You will weight" << weight2 << "on Mercury." <<endl;
                        }
                        That should do it
                        Actually, I would like to cout <<"Please make a selection."; each time the user gets ready to make a selection.
                        When I tried to place the please make a selection under the "what is your weight statement, this is what happened:

                        Program Section
                        cout << "Enter your weight: ";
                        cin >> weight1;
                        cout << "Please make a selection: ";

                        while (choice !=99)
                        {
                        cin >> choice;

                        if (choice == 1)
                        {

                        weight2 = weight1 * 0.40;
                        cout << "You will weight" << weight2 << "on Mercury." <<endl;
                        }


                        B]Output [/B]
                        Planet Menu

                        1. Mercury
                        2. Venus
                        3. Earth
                        4. Mars
                        5. Jupiter
                        6. Saturn
                        7. Uranus
                        8. Neptune
                        9. Pluto
                        99. Exit

                        Enter your weight: 185
                        Please make a selection: 3
                        You will weight185on Earth.
                        6
                        You will weight203.5on Saturn.
                        7
                        You will weight148on Uranus.
                        8
                        You will weight222on Neptune.
                        9
                        You will weight1.85on Pluto.
                        99

                        I am trying to make it look like this:
                        Enter your weight: 185
                        Please make a selection: 3
                        You will weight185on Earth.
                        Please make a selection: 6
                        You will weight203.5on Saturn.
                        Please make a selection: 7
                        You will weight148on Uranus.
                        Please make a selection: 8
                        You will weight222on Neptune.
                        Please make a selection: 9
                        You will weight1.85on Pluto.
                        99

                        So, do you have any idea how I can make the "Please make a selection" statement loop after each weight is calculated???

                        Thanks

                        Comment

                        • ilikepython
                          Recognized Expert Contributor
                          • Feb 2007
                          • 844

                          #13
                          Yea, just put the "cout << Please make a selection << endl;" line right above the "cin >> choice;" line.
                          like this:
                          Code:
                          while (choice is not 99)
                          {
                          cout << "Please make a selection" << endl;
                          cin >> choice;
                          
                          
                          // rest of stuff here
                          }

                          Comment

                          • namcintosh
                            New Member
                            • Apr 2007
                            • 67

                            #14
                            Originally posted by ilikepython
                            Yea, just put the "cout << Please make a selection << endl;" line right above the "cin >> choice;" line.
                            like this:
                            Code:
                            while (choice is not 99)
                            {
                            cout << "Please make a selection" << endl;
                            cin >> choice;
                            
                            
                            // rest of stuff here
                            }


                            OHMIGOODNESS!!! My program works, THANK GOD!! Thank you, thank you, thank you.

                            Now, I can finally rest tonight!!! I am definitely puttling you on my buddy list!! (LOL)

                            Comment

                            • ilikepython
                              Recognized Expert Contributor
                              • Feb 2007
                              • 844

                              #15
                              Originally posted by namcintosh
                              OHMIGOODNESS!!! My program works, THANK GOD!! Thank you, thank you, thank you.

                              Now, I can finally rest tonight!!! I am definitely puttling you on my buddy list!! (LOL)
                              You are very welcome.

                              Comment

                              Working...