Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. /* Connor Divelbess
  2.    Simple calculator capable of only single calculations, WILL LOOP IF ANYTHING ELSE IS ENTERED
  3.    */
  4. #include "stdafx.h"
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int _tmain(int nNumberofArgs, char* pszArgs[])
  12. {
  13.     int nOperand1;
  14.     int nOperand2;
  15.     char cOperator;
  16.     cout << "Enter 'value1 op value2' \n"
  17.          << "where op is +, -, *, / or %:" << endl;
  18.     top:
  19.     cin >> nOperand1 >> cOperator >> nOperand2;
  20.  
  21.     // echo input
  22.     cout << nOperand1 << " "
  23.          << cOperator << " "
  24.          << nOperand2 << " = ";
  25.  
  26.     switch (cOperator) // Begin legal input!
  27.     {
  28.     case '+':
  29.         cout << nOperand1 + nOperand2;
  30.     break;
  31.     case '-':
  32.         cout << nOperand1 - nOperand2;
  33.     break;
  34.     case '*':
  35.     case 'x':
  36.     case 'X':
  37.         cout << nOperand1 * nOperand2;
  38.         break;
  39.     case '/':
  40.         cout << nOperand1 / nOperand2;
  41.         break;
  42.     case '%':
  43.         cout << nOperand1 % nOperand2;
  44.         break;
  45.     default:
  46.         cout << "sorry, try again!";
  47.     }
  48.     cout << endl;
  49.  
  50.     goto top;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement