Advertisement
ItsWolfiy

Improving my C++ calculator u,u

Mar 3rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. restart_calculator:
  9. system("mode 58, 23");
  10.     char endChoice;
  11.     do{
  12.         system("cls");
  13.  
  14.         cout << "================\n C++ CALCULATOR\n================" << endl;
  15.  
  16.         //Input first number
  17.         cout << "\n\n Choose the first number (use \".\" for decimals): " << endl;
  18.         double firstNumber;
  19.         cin >> firstNumber;
  20.  
  21.         //Input second number
  22.         cout << "\n Now choose the second number (use \".\" for decimals): " << endl;
  23.         double secondNumber;
  24.         cin >> secondNumber;
  25.  
  26.         //Input operation
  27.         cout << "\n Choose your operation ( +, -, * or / )" << endl;
  28.         char operation;
  29.         cin >> operation;
  30.  
  31.         //Case switch for operations
  32.         switch(operation){
  33.         case '+':
  34.             {
  35.                 cout << "\n The result is: " << firstNumber + secondNumber << endl;
  36.                 break;
  37.             }
  38.         case '-':
  39.             {
  40.                 cout << "\n The result is: " << firstNumber - secondNumber << endl;
  41.                 break;
  42.             }
  43.         case '*':
  44.             {
  45.                 cout << "\n The result is: " << firstNumber * secondNumber << endl;
  46.                 break;
  47.             }
  48.         case '/':
  49.             {
  50.                 cout << "\n The result is: " << firstNumber / secondNumber << endl;
  51.                 break;
  52.             }
  53.         default:
  54.             {
  55.                 cout << "\n Please, next time, choose a valid operation!" << endl;
  56.             }
  57.         }
  58.  
  59.         cout << "\n\n--------------------------\nDeveloped by Wolfiy\n" << "\nMake another calcul? [Y/N]" << endl;
  60.  
  61.         //End Switch
  62.  
  63.         restart_ask:
  64.         cin >> endChoice;
  65.         switch(endChoice){
  66.         case 'N': case 'n':
  67.             {
  68.                 exit(0);
  69.             }
  70.         case 'Y': case 'y':
  71.             {
  72.                 continue;
  73.             }
  74.         default:
  75.             {
  76.                 do{
  77.                     cout << "\n Please, select between Y (yes) and N (no)." << endl;
  78.                     cin >> endChoice;
  79.                     if(endChoice == 'N' || 'n'){
  80.                         exit(0);
  81.                     }
  82.                     else if(endChoice == 'Y' || 'y'){
  83.                         goto restart_calculator;
  84.                     }
  85.                     else{
  86.                         goto restart_ask;
  87.                     }
  88.  
  89.                 }while(endChoice != 'Y' || 'y' || 'N' || 'n');
  90.             }
  91.         }
  92.  
  93.     }while(endChoice == 'Y', 'y');
  94.  
  95.         return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement