Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string start = "";
- double num1;
- double num2;
- double result;
- int a;
- while (a != 5)
- {
- cout << "Copyright © 2012 Evan Malz, All rights reserved\n" << endl;
- cout << "Type 'Go' to start the calculator, 'Help' for i"
- << "nstructions, or 'Exit' to quit\n" << endl;
- cin >> start;
- // Asks for inputs 'go' or 'help'
- cout << "\n" << endl;
- if (start == "exit")
- {
- cout << "Press Enter to exit. \n";
- cin.ignore();
- cin.get();
- return 0;
- // Exits program if user imputs 'exit'
- }
- if (start == "help")
- {
- cout << "For steps 1 and 2, you will be asked to enter 2 nu"
- << "mbers.\nFor step 3, you will choose an operation, "
- << "for example,\nfor multiplication you would type '1"
- << "'. You will return\nto Step 1 after receiving the "
- << "answer to your calculation" << endl;
- } // Text shown when 'help' is imput
- if (start == "go")
- {
- // Below is what will happen if the user imputs 'go'
- cout << "Step 1" << endl;
- cout << "Enter first integer: \n" << endl;
- // Asks for first number
- cin >> num1;
- // Defines 'num1' as the number imput above
- cout << "\n" << endl;
- cout << "Step 2" << endl;
- cout << "Enter second integer: \n" << endl;
- // Asks for second number
- cin >> num2;
- // Defines 'num2' as the number imput above
- cout << "\n" << endl;
- cout << "Step 3" << endl;
- cout << "Choose an operation below (Type only the number)"
- << "\n\n1 = Multiply (x) ---- 5 = Exit calculator\n"
- << "2 = Divide (/) \n3 = Add (+)\n4 = "
- << "Subtract (-)\n" << endl;
- // Asks for number of operation
- cin >> a;
- // Defines 'a' as the number imput above
- cout << "\n" << endl;
- }
- switch(a)
- {
- case 1:
- result = num1 * num2;
- cout << num1 << " x " << num2 << " = " << result << "\n"
- << "";
- cout << "\n" << endl;
- cout << "When you're finished, type '5' at Step 3 to ex"
- << "it\n" << endl;
- break;
- // This case is used if user types '1'. Selects multiplicat-
- // ion
- case 2:
- result = num1 / num2;
- cout << num1 << " / " << num2 << " = " << result << "\n"
- << "";
- cout << "\n" << endl;
- cout << "When you're finished, type '5' at Step 3 to ex"
- << "it\n" << endl;
- break;
- // This case is used if user types '2'. Selects division
- case 3:
- result = num1 + num2;
- cout << num1 << " + " << num2 << " = " << result << "\n"
- << "";
- cout << "\n" << endl;
- cout << "When you're finished, type '5' at Step 3 to ex"
- << "it\n" << endl;
- break;
- // This case is used if user types '3'. Selects addition
- case 4:
- result = num1 - num2;
- cout << num1 << " - " << num2 << " = " << result << "\n"
- << "";
- cout << "\n" << endl;
- cout << "When you're finished, type '5' at Step 3 to ex"
- << "it\n" << endl;
- break;
- // This case is used if user types '4'. Selects subtraction
- case 5:
- cout << "Thanks for using my calculator! Press Enter to"
- << "exit" << endl;
- // This case is used if user types '5'. Exits program
- cout << "Press enter to exit. \n";
- cin.ignore();
- cin.get();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement