Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Connor Divelbess
- Simple calculator capable of only single calculations, WILL LOOP IF ANYTHING ELSE IS ENTERED
- */
- #include "stdafx.h"
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int _tmain(int nNumberofArgs, char* pszArgs[])
- {
- int nOperand1;
- int nOperand2;
- char cOperator;
- cout << "Enter 'value1 op value2' \n"
- << "where op is +, -, *, / or %:" << endl;
- top:
- cin >> nOperand1 >> cOperator >> nOperand2;
- // echo input
- cout << nOperand1 << " "
- << cOperator << " "
- << nOperand2 << " = ";
- switch (cOperator) // Begin legal input!
- {
- case '+':
- cout << nOperand1 + nOperand2;
- break;
- case '-':
- cout << nOperand1 - nOperand2;
- break;
- case '*':
- case 'x':
- case 'X':
- cout << nOperand1 * nOperand2;
- break;
- case '/':
- cout << nOperand1 / nOperand2;
- break;
- case '%':
- cout << nOperand1 % nOperand2;
- break;
- default:
- cout << "sorry, try again!";
- }
- cout << endl;
- goto top;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement