Problem with do-while loop

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 19
Reputation: newbie2c++ is an unknown quantity at this point 
Solved Threads: 0
newbie2c++ newbie2c++ is offline Offline
Newbie Poster

Problem with do-while loop

 
0
  #1
Nov 1st, 2006
Hi all! THis is the program I am supposed to write:
Modify the program so it displays a menu allowing the user to select an addition, subtraction, multiplication, or division problem. The final selection on the menu should let the user quit the program. After the user has finished the math problem, the program should display the menu again. This process is repeated until the user chooses to quit the program.
  • Input Validation: If the user selects an item not on the menu, display an error message and display the menu again.
Additional notes to pc4:
  • Do not implement the subtraction, multiplication, or division. Instead, provide a message to the effect that the module is not yet ready.
  • Use a switch statement to process menu choices.
  • Use a 'do while' loop, as shown below.
  • Here is pseudocode of what should go in the do loop for this exercise:
  • do { 1. addition
  • 2. subtraction
  • 3. etc
  • 5. quit Which would you like?
  • switch (choice)
  • case 1: the whole program you already wrote
  • case 2: not available etc.
  • case 5: Thank you and goodbye!
  • default: got to be kidding, try again! }
  • while( choice != 5 ); 'do while' loops and 'switch' work great for menus. The screen capture for this assignment should demonstrate a 'Not Available' and 'Exit' choice
The problem I am having is that it won't compile and I"m not sure why. This is the code I have so far does anyone know what I'm doing wrong?
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int choice; // menu choice
  9.  
  10. cout << "This program written by Katy Pedro cs102 Online." << endl;
  11.  
  12. do
  13. {
  14. cout << " MENU " << endl;
  15. cout << " 1. Addition\n";
  16. cout << " 2. Subtraction\n";
  17. cout << " 3. Multiplication\n";
  18. cout << " 4. Division\n";
  19. cout << " 5. Quit the program\n";
  20. cout << "_____________________\n";
  21.  
  22.  
  23. while (choice < 1 || choice > 5)
  24. {
  25. cout << "Enter your selection: ";
  26. cin >> choice;
  27. }
  28. if (choice !=5)
  29. {
  30. cout << "I'm sorry but that is not available!" << endl;
  31.  
  32. switch (choice)
  33. {
  34. case 1: cout << "Please make a different choice, this program is not available.\n";
  35. break;
  36. case 2: cout << "Please make a different choice, this program is not available.\n";
  37. break;
  38. case 3: cout << "Please make a different choice, this program is not available.\n";
  39. break;
  40. case 4: cout << "Please make a different choice, this program is not available.\n";
  41. break;
  42. case 5: "Thank you for making the right choice! GOODBYE for now!\n";
  43. break;
  44. default: cout << "Are you serious? Try Again!!!\n";
  45. }
  46.  
  47. system("PAUSE");
  48. return 0;
  49.  
  50. }

THanks in advance any help is greatly appreciated!!!:cheesy:
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Problem with do-while loop

 
0
  #2
Nov 1st, 2006
  1. if (choice !=5)
  2.  
  3. {
  4.  
  5. cout << "I'm sorry but that is not available!" << endl;
You forgot to add a closing brace.

  1. system("PAUSE");
  2.  
  3. return 0;
You never ended the do loop; do loops require a closing brace and a while statement to follow.

And lastly, you never ended the main function! A closing brace is all that's needed.
Last edited by John A; Nov 1st, 2006 at 9:35 pm.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: Problem with do-while loop

 
0
  #3
Nov 2nd, 2006
Here's something that you might find useful. Because the description of the problem isnt really the clearest it could be, I made this little program up to help you understand what should happen. Its using a functino called DoMenu which displays the menu and gets input from there.
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int DoMenu();
  6.  
  7. int main()
  8. {
  9. int choice;
  10. do
  11. {
  12. choice = DoMenu();
  13.  
  14. switch (choice)
  15. {
  16. case 1: cout << "addition\n"; break;
  17. case 2: cout << "subtraction\n"; break;
  18. case 3: cout << "multiplication\n"; break;
  19. case 4: cout << "division\n"; break;
  20. case 5: cout << "quit\n"; break;
  21. default : cout << "Error input\n";
  22. }
  23.  
  24. } while (choice != 5);
  25.  
  26. return 0;
  27. }
  28.  
  29. int DoMenu()
  30. {
  31. int MenuChoice;
  32. cout << " MENU\n";
  33. cout << " 1. Addition\n";
  34. cout << " 2. Subtraction\n";
  35. cout << " 3. Multiplication\n";
  36. cout << " 4. Division\n";
  37. cout << " 5. Quit the program\n";
  38. cout << "_____________________\n";
  39. cin >> MenuChoice;
  40. return MenuChoice;
  41. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: leika is an unknown quantity at this point 
Solved Threads: 0
leika leika is offline Offline
Newbie Poster
 
-3
  #4
Oct 11th, 2009
Create an application that will input any integer values and display it in reverse using looping in visual basic 2008. please answer thanks^^
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso
 
0
  #5
Oct 12th, 2009
A. You are responding to a three year old post
B. You are hijacking that thread with a new problem
C. You are asking for a solution to a problem you have not attempted to solve on your own
D. This is a C++ forum, you're asking for a VB program

Read the sticky threads at the beginning of the forums, and chose the correct forum for your problem. You might then get some help.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC