Facebook
From s, 3 Months ago, written in C++.
Embed
Download Paste or View Raw
Hits: 215
  1. #include <iostream>
  2.  
  3. int chooseOperator()
  4. {
  5.     std::string operatorInput;
  6.     std::cout << "btw im adding more features, and mod, inc, dec aint working yet\n";
  7.     std::cout << "What operator would you like to use (sub, div, add, mul, mod, inc, dec)?: ";
  8.     std::cin >> operatorInput;
  9.  
  10.     int operandDecider;
  11.     if (operatorInput == "sub")
  12.         operandDecider = 1;
  13.  
  14.     else if (operatorInput == "div")
  15.         operandDecider = 2;
  16.  
  17.     else if (operatorInput == "add")
  18.         operandDecider = 3;
  19.  
  20.     else if (operatorInput == "mul")
  21.         operandDecider = 4;
  22.  
  23.     else if (operatorInput == "mod")
  24.         operandDecider = 5;
  25.  
  26.     else if (operatorInput == "inc")
  27.         operandDecider = 6;
  28.  
  29.     else if (operatorInput == "dec")
  30.         operandDecider = 7;
  31.  
  32.     return operandDecider;
  33. }
  34.  
  35. void process(int operandDecider, double num1, double num2, bool question)
  36. {
  37.     switch (operandDecider)
  38.     {
  39.     case 1:
  40.         std::cout << num1 - num2 << "\n";
  41.          questi
  42.         break;
  43.     case 2:
  44.         std::cout << num1 / num2 << "\n";
  45.          questi
  46.         break;
  47.     case 3:
  48.         std::cout << num1 + num2 << "\n";
  49.          questi
  50.         break;
  51.     case 4:
  52.         std::cout << num1 * num2 << "\n";
  53.          questi
  54.         break;
  55.     default:
  56.         break;
  57.     }
  58. }
  59.  
  60. void AskIfWantUse(std::string &isYes;, bool &InvalidInput;, bool &Question;)
  61.     {std::cout << "Want to use calculator? (Y/N): ";
  62.     std::cin >> isYes;
  63.     std::string exited;
  64.  
  65.     if (isYes == "Y"){
  66.         InvalidInput = false;
  67.         Question = true;}
  68.    
  69.     else if (isYes == "N"){
  70.         InvalidInput = false;
  71.         Question = false;}
  72.  
  73.         while (InvalidInput == true)
  74.         {
  75.            std::cout << "Invalid Input! (Y/N): ";
  76.            std::cin >> isYes;
  77.            if (isYes == "Y")
  78.            break;
  79.  
  80.            if (isYes == "N")
  81.             break;
  82.    
  83.         }
  84.     if (isYes == "N")
  85.     {
  86.         std::cout << "Exited Program";
  87.         std::cin >> exited;
  88.         Question = false;
  89.     }
  90. }
  91.  
  92. int main()
  93. {
  94.     double num1;
  95.     double num2;
  96.     int operandDecider;
  97.     std::string isYes;
  98.     bool InvalidInput = true;
  99.     bool Question = false;
  100.  
  101.     std::cout << "Welcome to Calculator\n";
  102.     AskIfWantUse(isYes, InvalidInput, Question);
  103.  
  104.      if (Questi true){
  105.         std::cout << "Enter number 1: ";
  106.         std::cin >> num1;
  107.         std::cout << "Enter number 2: ";
  108.         std::cin >> num2;
  109.         operandDecider = chooseOperator();
  110.         process(operandDecider, num1, num2, Question); }
  111.    
  112.  
  113.     while (Question == true)
  114.     {
  115.         AskIfWantUse(isYes, InvalidInput, Question);
  116.         if (isYes == "N"){
  117.                 break;
  118.         }
  119.  
  120.         std::cout << "Enter number 1: ";
  121.         std::cin >> num1;
  122.         std::cout << "Enter number 2: ";
  123.         std::cin >> num2;
  124.         operandDecider = chooseOperator();
  125.         process(operandDecider, num1, num2, Question);
  126.     }
  127.  
  128.     return 0;
  129. }
  130.