| | |
Problem with do-while loop
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 19
Reputation:
Solved Threads: 0
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.
THanks in advance any help is greatly appreciated!!!:cheesy:
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.
- 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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; int main() { int choice; // menu choice cout << "This program written by Katy Pedro cs102 Online." << endl; do { cout << " MENU " << endl; cout << " 1. Addition\n"; cout << " 2. Subtraction\n"; cout << " 3. Multiplication\n"; cout << " 4. Division\n"; cout << " 5. Quit the program\n"; cout << "_____________________\n"; while (choice < 1 || choice > 5) { cout << "Enter your selection: "; cin >> choice; } if (choice !=5) { cout << "I'm sorry but that is not available!" << endl; switch (choice) { case 1: cout << "Please make a different choice, this program is not available.\n"; break; case 2: cout << "Please make a different choice, this program is not available.\n"; break; case 3: cout << "Please make a different choice, this program is not available.\n"; break; case 4: cout << "Please make a different choice, this program is not available.\n"; break; case 5: "Thank you for making the right choice! GOODBYE for now!\n"; break; default: cout << "Are you serious? Try Again!!!\n"; } system("PAUSE"); return 0; }
THanks in advance any help is greatly appreciated!!!:cheesy:
c Syntax (Toggle Plain Text)
if (choice !=5) { cout << "I'm sorry but that is not available!" << endl;
c Syntax (Toggle Plain Text)
system("PAUSE"); return 0;
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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int DoMenu(); int main() { int choice; do { choice = DoMenu(); switch (choice) { case 1: cout << "addition\n"; break; case 2: cout << "subtraction\n"; break; case 3: cout << "multiplication\n"; break; case 4: cout << "division\n"; break; case 5: cout << "quit\n"; break; default : cout << "Error input\n"; } } while (choice != 5); return 0; } int DoMenu() { int MenuChoice; cout << " MENU\n"; cout << " 1. Addition\n"; cout << " 2. Subtraction\n"; cout << " 3. Multiplication\n"; cout << " 4. Division\n"; cout << " 5. Quit the program\n"; cout << "_____________________\n"; cin >> MenuChoice; return MenuChoice; }
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.
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Random Number Problem For Lottery Program (Visual Basic 4 / 5 / 6)
- C++ Calculating even Values Problem (C++)
- problem in displayin records on a form (VB.NET)
- C++ Newbie, stumped with problem (C++)
- help with my for loop (C++)
- My loop won't work, but I'm positive it should. (Python)
- PHP + MySQL Problem (PHP)
- Help with while loop for hangman project (C++)
- varible not working in for loop (Java)
- Help with loop (C++)
Other Threads in the C++ Forum
- Previous Thread: Problem with doubles and floats, apparently
- Next Thread: Infix Parentheses Balancing
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






