Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1.     int outcome = 0;
  2.     int sum = 0;
  3.     int difference = 0;
  4.     char op = ' ';
  5.     char a = '+';
  6.     char b = '-';
  7.     char c = ';';
  8.     char d = '^';
  9.         cin >>outcome;
  10.     while (cin >> op){ // While the reading operation is a success
  11.         if (op == d) {
  12.             outcome = outcome * outcome
  13.                     }
  14.        
  15.         else if (op == a){ //Checks if operator is +
  16.                     cin>>sum;
  17.                     cin >> op;
  18.                     if (op == d){
  19.                         sum = sum * sum;
  20.                         outcome = outcome + sum;
  21.                     }
  22.                     else{
  23.                     outcome = outcome + sum;
  24.                     }
  25.                     }
  26.                     else if (op==b){ //checks if operator is -
  27.                             cin>>difference;
  28.                             cin>>op;
  29.                             if (op == d){
  30.                                 difference = difference * difference;
  31.                                 outcome = outcome - difference;
  32.                             }
  33.                             else{
  34.                             outcome = outcome-difference;
  35.                     }}
  36.                     else if (op == c){ //checks if operator is ; and resets the outcome value
  37.                             cout << outcome << endl;
  38.                             cin >> sum;
  39.                             outcome = 0;
  40.                             outcome = outcome+sum;
  41.                            
  42.                            
  43.                     }
  44.                     else{
  45.                             cout << "Operator is invalid" << endl;
  46.                             return 0;
  47.                     }
  48.     }
  49.  
  50.    
  51.     return 0;
  52.    
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement