Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6.     double num1;
  7.     double num2;
  8.     double num3;
  9.     string yesorno;
  10.     string yesorno2;
  11.     string operator1;
  12.    
  13.     void mean();
  14.     void pausewithtext();
  15.     void gotomain();
  16.    
  17. int main()
  18. {
  19.  
  20.    
  21.     printf ("\nThis program will let you +, -, * or / numbers\n Please enter the operator you wish to use: ");
  22.            cin >> operator1; cout << endl;
  23.     printf ("Please enter the first number you wish to use: ");
  24.            cin >> num1; cout << endl;
  25.     printf ("Please enter the second number you wish to use: ");
  26.            cin >> num2; cout << endl;
  27.     printf ("Do you want to use a 3rd number? (y/n)");
  28.            cin >> yesorno; cout << endl;
  29.                 if ((yesorno == "y") || (yesorno == "Y")) {
  30.                     printf("Please enter the third number you wish to use: ");                
  31.                     cin >> num3;
  32.                    
  33.                                 /* This is the code for actual calculating (3 numbers) */
  34.                             if (operator1 == "+")
  35.                                {
  36.                                     mean();
  37.                                    //Addition for 3 numbers
  38.                                     cout << "Answer: " << num1 + num2 + num3 << endl;
  39.                                     pausewithtext();
  40.                                     gotomain();              
  41.                                }
  42.                                else if (operator1 == "-")
  43.                                {
  44.                                    //Subtraction for 3 numbers
  45.                                    cout << "Answer: " << num1 - num2 - num3 << endl;
  46.                                    pausewithtext();
  47.                                    gotomain();
  48.                                }
  49.                                else if (operator1 == "/")
  50.                                {
  51.                                    //Division for 3 numbers
  52.                                    cout << "Answer: " << num1 / num2 / num3 << endl;
  53.                                    pausewithtext();
  54.                                    gotomain();
  55.                                }
  56.                                else if (operator1 == "*")
  57.                                {
  58.                                    //Multiplication for 3 numbers
  59.                                    cout << "Answer: " << num1 * num2 * num3 << endl;
  60.                                     pausewithtext();
  61.                                     gotomain();
  62.                                }
  63.                                else
  64.                                {
  65.                                     printf("This happenes when the operator does not == /, +, - or * with 3 numbers");
  66.                                     pausewithtext();
  67.                                     gotomain();
  68.                                }
  69.                                 /* End calculating (3 numbers)*/
  70.                 }
  71.                 else
  72.                 {
  73.                  
  74.                                 /* This is the code for actual calculating (2 numbers) */
  75.                             if (operator1 == "+")
  76.                                {
  77.                                    //Addition with 2 numbers
  78.                                    cout << "Answer :" << num1 + num2 << endl;
  79.                                    pausewithtext();
  80.                                    gotomain();
  81.                                }
  82.                                else if (operator1 == "-")
  83.                                {
  84.                                    //Subtraction with 2 numbers
  85.                                    cout << "Answer: " << num1 - num2 << endl;
  86.                                    pausewithtext();
  87.                                    gotomain();
  88.                                }
  89.                                else if (operator1 == "/")
  90.                                {
  91.                                    //Division with 2 numbers
  92.                                    cout << "Answer: " << num1 / num2 << endl;
  93.                                    pausewithtext();
  94.                                    gotomain();
  95.                                }
  96.                                else if (operator1 == "*")
  97.                                {
  98.                                    //Multiplication with 2 numbers
  99.                                    cout << num1 * num2 << endl;
  100.                                     gotomain();
  101.                                }
  102.                                else
  103.                                {
  104.                                     printf("This happens when the operator does not == /, +, - or * with 3 numbers");
  105.                                     pausewithtext();
  106.                                     gotomain();
  107.                                }
  108.                                 /* End calculating (2 numbers)*/
  109.                  
  110.                 }      
  111. }
  112.                        
  113.    
  114. void mean()
  115. {
  116.      printf ("\nDo you want to use take the mean of your numbers? (y/n)");
  117.            cin >> yesorno; cout << endl;
  118.                 if ((yesorno == "y") || (yesorno == "Y"))
  119.                 {
  120.                         cout << "The answer is: " << (num1 + num2 + num3) / 3 << endl;
  121.                         pausewithtext();
  122.                         gotomain();    
  123.                 }
  124.                 else
  125.                 {
  126.                 }
  127.                 }
  128.  
  129. void pausewithtext()
  130. {
  131.      cout << "Press any key to continue...";
  132.      getch();
  133.      }  
  134.      
  135. void gotomain()
  136. {
  137.      main();
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement