Need Help

Hey I'm just starting to understand C++. I'm doing a problem for my class and I can't finish the problem I'm drawing a complete blank. It's probably something very simple.

Here's the question

Create menu system using a switch statement. Ask the user to input a command based on a menu and display the appropriate message. Your program should continue to ask the user for commands until they enter a specific number. Your menu system can say anything as long as you use a switch statement to determine the command.



And here is my code:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
enum operations {addition = 1, subtraction, multiplication, division, 5};
int command;
float x , y;


cout << "Please pick a command:" << endl;
cout << "1. Addition:" << endl;
cout << "2. Subtraction:" << endl;
cout << "3. Multiplication:" << endl;
cout << "4. Division:" << endl;
cout << "5. Exit:" << endl;


cin >> command;

do
{

switch (command)
{

case addition:
cout << "Enter addition problem" << endl;
cin >> x;
cin >> y;
cout << x + y << endl;
break;

case subtraction:

cout << "Enter subtraction problem" << endl;
cin >> x;
cin >> y;
cout << x - y << endl;
break;

case multiplication:
cout << "Enter multiplication problem" << endl;
cin >> x;
cin >> y;
cout << x * y << endl;
break;

case division:

cout << "Enter division problem" << endl;
cin >> x;
cin >> y;
cout << x / y << endl;
break;

case 5:

cout << "Thanks for using this program" << endl;
break;
}
}
while (command);

system ("pause");
return 0;
}


Hey
So I didn't read all of your code, but I did notice some things I would change just from reading the loop.

First I would include your cout statments in the do while loop so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
do{

cout << "Please pick a command:" << endl;
cout << "1. Addition:" << endl;
cout << "2. Subtraction:" << endl;
cout << "3. Multiplication:" << endl;
cout << "4. Division:" << endl;
cout << "5. Exit:" << endl;


cin >> command;


switch (command)
{
//etc


Also when you are declaring your enum, you don't need the 5 at the end.
 
enum operations {addition = 1, subtraction, multiplication, division};


and last but not least your while loop doesn't really end, instead of having:
while (command);
which will always be true

try something like:
while (command != 5); //so if the user ever inputs 5, this will be false and end your loop


If your still having issues, I'll take a deeper look into for you ^_^
It worked!! :D Thanks so much. I knew it was a easy problem lol xD
Topic archived. No new replies allowed.