Guest User

Calculator 1.4.5.0 Source Code

a guest
Apr 20th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.     string start = "";
  10.  
  11.     double num1;
  12.     double num2;
  13.     double result;
  14.     int a;
  15.  
  16.     while (a != 5)
  17.     {
  18.         cout << "This calculator was made by Evan Malz\n" << endl;
  19.         cout << "Type 'Go' to start the calculator, 'Help' for i"
  20.              << "nstructions, or 'Exit' to quit\n" << endl;
  21.         cin >> start;
  22.         // Asks for inputs 'go' or 'help'
  23.         cout << "\n" << endl;
  24.  
  25.         if (start == "exit")
  26.         {
  27.             cout << "Press Enter to exit. \n";
  28.             cin.ignore();
  29.             cin.get();
  30.             return 0;
  31.             // Exits program if user imputs 'exit'
  32.         }
  33.  
  34.         if (start == "help")
  35.         {
  36.             cout << "For steps 1 and 2, you will be asked to enter 2 nu"
  37.                  << "mbers.\nFor step 3, you will choose an operation, "
  38.                  << "for example,\nfor multiplication you would type '1"
  39.                  << "'. You will return\nto Step 1 after receiving the "
  40.                  << "answer to your calculation,\nand in order to exit,"
  41.                  << " you have to type '5' when you are\nat Step 3.\n"
  42.                  << endl;
  43.         }    // Text shown when 'help' is imput
  44.  
  45.         if (start == "go")
  46.         {
  47.             // Below is what will happen if the user imputs 'go'
  48.  
  49.             cout << "Step 1" << endl;
  50.             cout << "Enter first integer: \n" << endl;
  51.             // Asks for first number
  52.  
  53.             cin >> num1;
  54.             // Defines 'num1' as the number imput above
  55.  
  56.             cout << "\n" << endl;
  57.  
  58.             cout << "Step 2" << endl;
  59.             cout << "Enter second integer: \n" << endl;
  60.             // Asks for second number
  61.  
  62.             cin >> num2;
  63.             // Defines 'num2' as the number imput above
  64.  
  65.             cout << "\n" << endl;
  66.  
  67.             cout << "Step 3" << endl;
  68.             cout << "Choose an operation below (Type only the number)"
  69.                  << "\n\n1 = Multiply (x) ---- 5 = Exit calculator\n"
  70.                  << "2 = Divide   (/)           \n3 = Add      (+)\n4 = "
  71.                  << "Subtract (-)\n" << endl;
  72.             // Asks for number of operation
  73.  
  74.             cin >> a;
  75.             // Defines 'a' as the number imput above
  76.  
  77.             cout << "\n" << endl;
  78.         }
  79.  
  80.         switch(a)
  81.         {
  82.         case 1:
  83.             result = num1 * num2;
  84.             cout << num1 << " x " << num2 << " = " << result << "\n"
  85.                  << "";
  86.             cout << "\n" << endl;
  87.             cout << "When you're finished, type '5' at Step 3 to ex"
  88.                  << "it\n" << endl;
  89.             break;
  90.             // This case is used if user types '1'. Selects multiplicat-
  91.             // ion
  92.  
  93.         case 2:
  94.             result = num1 / num2;
  95.             cout << num1 << " / " << num2 << " = " << result << "\n"
  96.                  << "";
  97.             cout << "\n" << endl;
  98.             cout << "When you're finished, type '5' at Step 3 to ex"
  99.                  << "it\n" << endl;
  100.             break;
  101.             // This case is used if user types '2'. Selects division
  102.  
  103.         case 3:
  104.             result = num1 + num2;
  105.             cout << num1 << " + " << num2 << " = " << result << "\n"
  106.                  << "";
  107.             cout << "\n" << endl;
  108.             cout << "When you're finished, type '5' at Step 3 to ex"
  109.                  << "it\n" << endl;
  110.             break;
  111.             // This case is used if user types '3'. Selects addition
  112.  
  113.         case 4:
  114.             result = num1 - num2;
  115.             cout << num1 << " - " << num2 << " = " << result << "\n"
  116.                  << "";
  117.             cout << "\n" << endl;
  118.             cout << "When you're finished, type '5' at Step 3 to ex"
  119.                  << "it\n" << endl;
  120.             break;
  121.             // This case is used if user types '4'. Selects subtraction
  122.  
  123.         case 5:
  124.             cout << "Thanks for using my calculator! Press Enter to"
  125.                  << "exit" << endl;
  126.             // This case is used if user types '5'. Exits program
  127.             cout << "Press enter to exit. \n";
  128.             cin.ignore();
  129.             cin.get();
  130.             return 0;
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment