sicotic87

Basic calc missing main menu loop

Aug 4th, 2012
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. // Basic calculator MISSING MAIN MENU LOOP
  2. #include <iostream>
  3. #include <conio.h>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.  
  14.    
  15.     int choice;
  16.  
  17.    
  18.     //Main Menu
  19.     cout << "Enter the number next to the calculation you would like to use, or \n if you would like to exit." << endl;
  20.     cout << endl;
  21.     cout << endl;
  22.     cout << "1. Addition" << endl;
  23.     cout << "2. Subtraction" << endl;
  24.     cout << "3. Multiplication" << endl;
  25.     cout << "4. Division" << endl;
  26.     cout << "5. Exit" << endl;
  27.     cout << endl;
  28.     cout << endl;
  29.     cin >> choice;
  30.  
  31.    
  32.     //Addition statement
  33.             if (choice == 1)
  34.     {
  35.         double firstNumber;
  36.         double secondNumber;
  37.         double result;
  38.  
  39.  
  40.             cout << "You chose addition." << endl;
  41.             cout << endl;
  42.             cout << "Enter the first number: ";
  43.             cin >> firstNumber;
  44.             cout << endl;
  45.             cout << "Now, enter the second number to add: ";
  46.             cin >> secondNumber;
  47.             cout << endl;
  48.            
  49.             result = firstNumber + secondNumber;
  50.  
  51.             cout << firstNumber << " + " << secondNumber << " = " << result << endl;
  52.             cout << endl;
  53.             cout << endl;
  54.             cout << "Press any key to exit.";
  55.            
  56.             getch();
  57.             return 0;
  58.     }
  59.    
  60.             //Subtraction statement
  61.     else if (choice == 2)
  62.     {
  63.         double firstNumber;
  64.         double secondNumber;
  65.         double result;
  66.  
  67.         cout << "You chose subtraction." << endl;
  68.         cout << endl;
  69.         cout << "Enter the first number: ";
  70.         cin >> firstNumber;
  71.         cout << endl;
  72.         cout << "Enter the second number to subtract: ";
  73.         cin >> secondNumber;
  74.         cout << endl;
  75.  
  76.         result = firstNumber - secondNumber;
  77.  
  78.         cout << firstNumber << " - " << secondNumber << " = " << result << endl;
  79.         cout << endl;
  80.         cout << endl;
  81.         cout << "Press any key to exit.";
  82.         getch();
  83.         return 0;
  84.     }
  85.             //Multiplication statement
  86.     else if (choice == 3)
  87.     {
  88.  
  89.         double firstNumber;
  90.         double secondNumber;
  91.         double result;
  92.  
  93.         cout << "You chose multiplication." << endl;
  94.         cout << endl;
  95.         cout << "Enter the first number: ";
  96.         cin >> firstNumber;
  97.         cout << endl;
  98.         cout << "Enter the second number to multiply: ";
  99.         cin >> secondNumber;
  100.         cout << endl;
  101.        
  102.         result = firstNumber * secondNumber;
  103.  
  104.         cout << firstNumber << " * " << secondNumber << " = " << result << endl;
  105.         cout << endl;
  106.         cout << endl;
  107.         cout << "Press any key to exit.";
  108.         getch();
  109.         return 0;
  110.     }
  111.     //Division statement
  112.     else if (choice == 4)
  113.     {
  114.         double firstNumber;
  115.         double secondNumber;
  116.         double result;
  117.  
  118.         cout << "You chose division." << endl;
  119.         cout << endl;
  120.         cout << "Enter the first number: ";
  121.         cin >> firstNumber;
  122.         cout << endl;
  123.         cout << "Enter the second number to divide: ";
  124.         cin >> secondNumber;
  125.         cout << endl;
  126.        
  127.         result = firstNumber / secondNumber;
  128.  
  129.         cout << firstNumber << " / " << secondNumber << " = " << result << endl;
  130.         cout << endl;
  131.         cout << endl;
  132.         cout << "Press any key to exit.";
  133.         getch();
  134.         return 0;
  135.     }
  136.     //Exit statement
  137.     else if (choice == 5)
  138.     {
  139.         return 0;
  140.     }
  141.    
  142.     //Loop after invalid choice
  143.     do
  144.     {
  145.        
  146.         cout << "You entered an invalid choice." << endl;
  147.         cout << "Please choose one of the following:" << endl;
  148.         cout << endl;
  149.         cout << endl;
  150.         cout << "1. Addition" << endl;
  151.         cout << "2. Subtraction" << endl;
  152.         cout << "3. Multiplication" << endl;
  153.         cout << "4. Division" << endl;
  154.         cout << "5. Exit" << endl;
  155.         cout << endl;
  156.         cin >> choice;
  157.     }
  158.     while (choice < 1 || choice > 5);
  159.    
  160.  
  161.    
  162.  
  163.         cout << endl;
  164.         cout << endl;
  165.         cout << endl;
  166.         cout << "Press any key to exit.";
  167.         getch();
  168.         return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment