Sep 23, 2019 at 1:09am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void showMenu();
void hello();
void add();
void subtract();
void multiply();
void divide();
int number1, number2;
int numTotal;
int enter;
int main()
{
int choice;
// constants for menu
const int MULTIPLY_CHOICE = 1,
DIVIDE_CHOICE = 2,
ADD_CHOICE = 3,
SUBTRACT_CHOICE = 4,
QUIT_CHOICE = 5;
//sets decimal point to two
do
{
//shows menu
showMenu();
cin >> choice;
//validates menu
while (choice < MULTIPLY_CHOICE || choice > QUIT_CHOICE)
{
cout << "please enter a valid menu choice" << endl;
cin >> choice;
}
// if user does not want to quit the code will continue
if (choice != QUIT_CHOICE)
{
switch (choice)
{
case MULTIPLY_CHOICE:
multiply();
break ;
case DIVIDE_CHOICE:
divide();
break ;
case ADD_CHOICE:
add();
break ;
case SUBTRACT_CHOICE:
subtract();
break ;
}
}
}while (choice != QUIT_CHOICE);
return 0;
}
// addition choice
void add()
{
cout << "Hello, please enter the two numbers you wish to use" << endl;
cin >> number1 >> number2;
numTotal = number1 + number2;
cout << numTotal << endl;
}
// subtract choice
void subtract()
{
cout << "Hello, please enter the two numbers you wish to use" << endl;
cin >> number1 >> number2;
numTotal = number1 - number2;
cout << numTotal << endl;
}
// multiply choice
void multiply()
{
cout << "Hello, please enter the two numbers you wish to use" << endl;
cin >> number1 >> number2;
numTotal = number1 * number2;
cout << numTotal << endl;
}
//divide choice
void divide()
{
cout << "Hello, please enter the two numbers you wish to use" << endl;
cin >> number1 >> number2;
numTotal = number1 / number2;
cout << numTotal << endl;
}
//menu choices
void showMenu()
{
cout << "Please choose a option (1-5)" << endl << endl
<< "1. multiplication" << endl
<< "2. division" << endl
<< "3. addition" << endl
<< "4. subtraction" << endl
<< "5. quit " << endl << endl;
}
Last edited on Sep 23, 2019 at 1:20am UTC
Sep 23, 2019 at 1:15am UTC
You have the user inputting their choice into "choice" the first time, but then you switch based on "enter". So the program is inconsistent.
Also, please edit your post to add code formatting by adding [ code] and [ /code] around your code.
Sep 23, 2019 at 1:19am UTC
I have changed it back so now all the enters are choice and it still wont print
Sep 23, 2019 at 1:22am UTC
Please choose a option (1-5)
1. multiplication
2. division
3. addition
4. subtraction
5. quit
1
Hello, please enter the two numbers you wish to use
2 3
6
Please choose a option (1-5)
1. multiplication
2. division
3. addition
4. subtraction
5. quit
5
The "happy path" test works for me. What is your input that doesn't work?
Last edited on Sep 23, 2019 at 1:24am UTC
Sep 23, 2019 at 1:26am UTC
So was running it on my laptop and it wasn't working but as soon as I ran it on my desktop is worked perfectly fine. So I'm not sure what the problem was.
Sep 23, 2019 at 2:36am UTC
Try creating a completely new project and re-paste the code in.