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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include <iostream>
int main()
{
char menuinput, p2m;
int plus1, plus2, plus3, min1, min2, min3, mul1, mul2, mul3;
double div1, div2, div3;
//main menu
mainmenu:
for (;;) {
do {
std::cout << "********************************************\nWelcome to Michael's Standard Calculator v1.\n********************************************\n\n\n\n";
std::cout << "Enter 1 for plus!\nEnter 2 for minus!\nEnter 3 for multiply\nEnter 4 for divi\nEnter q to quit (case sensitive)\n";
std::cin >> menuinput;
}
while (menuinput < '1' || menuinput > '4'&& menuinput != 'q');
//The actual calculators
if (menuinput == 'q'){
goto Programend;
}
switch (menuinput)
{
//Plus calculator
case '1':
plus:
std::cout << "Enter the first number: ";
std::cin >> plus1;
std::cout << "Enter the second number: ";
std::cin >> plus2;
plus3 = plus1 + plus2;
std::cout << plus1 << " + " << plus2 << " = " << plus3 << "\n\n"; //Display plus
std::cout << "Enter b to do another calculation\nEnter m to go back to the main menu\nEnter q to quit\n\n";
inv1:
std::cin >> p2m;
if (p2m == 'b') goto plus;
else if (p2m == 'm') goto mainmenu;
else if (p2m == 'q') goto Programend;
else {
std::cout << "You have selected an invalid option, please try again.";
goto inv1;
}
break;
case '2':
minus:
std::cout << "Enter the first number: ";
std::cin >> min1;
std::cout << "Enter the second number: ";
std::cin >> min2;
min3 = min1 - min2;
std::cout << min1 << " - " << min2 << " = " << min3 << "\n\n"; //Display plus
std::cout << "Enter b to do another calculation\nEnter m to go back to the main menu\nEnter q to quit\n\n";
inv2:
std::cin >> p2m;
if (p2m == 'b') goto minus;
else if (p2m == 'm') goto mainmenu;
else if (p2m == 'q') goto Programend;
else {
std::cout << "You have selected an invalid option, please try again.";
goto inv2;
}
break;
case '3':
multiply:
std::cout << "Enter the first number: ";
std::cin >> mul1;
std::cout << "Enter the second number: ";
std::cin >> mul2;
mul3 = mul1 * mul2;
std::cout << mul1 << " X " << mul2 << " = " << mul3 << "\n\n"; //Display plus
std::cout << "Enter b to do another calculation\nEnter m to go back to the main menu\nEnter q to quit\n\n";
inv3:
std::cin >> p2m;
if (p2m == 'b') goto multiply;
else if (p2m == 'm') goto mainmenu;
else if (p2m == 'q') goto Programend;
else {
std::cout << "You have selected an invalid option, please try again.\n";
goto inv3;
}
break;
case '4':
division:
std::cout << "Enter the first number: ";
std::cin >> div1;
std::cout << "Enter the second number: ";
std::cin >> div2;
div3 = div1 / div2;
std::cout << div1 << " X " << div2 << " = " << div3 << "\n\n"; //Display plus
std::cout << "Enter b to do another plus calculation\nEnter m to go back to the main menu\nEnter q to quit";
inv4:
std::cin >> p2m;
if (p2m == 'b') goto division;
else if (p2m == 'm') goto mainmenu;
else if (p2m == 'q') goto Programend;
else {
std::cout << "You have selected an invalid option, please try again.\n";
goto inv4;
}
break;
}
}
//Program end!
Programend:
std::cout << "Thank you for using the program! ENTER ANY KEY TO QUIT! ";
std::cin.get();
std::cin.ignore();
return 0;
}
|