Last active
August 29, 2015 14:02
-
-
Save dd1994/2a5c5bcbe00c53951abf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int flag; | |
| long int a, b; | |
| long double result; | |
| char operation; | |
| cout << "input two Integers(one space between them), then press Enter:" << endl; | |
| while(cin >> a >> b){ | |
| cout << "input +, -, *, or / , then press Enter: " << endl; | |
| cin >> operation; | |
| if (0 == b && '/' == operation) | |
| { | |
| cout << "error: integer division by zero" << endl; | |
| } | |
| else | |
| { | |
| flag = 0; | |
| switch(operation) | |
| { | |
| case '+': | |
| result = a + b; | |
| break; | |
| case '-': | |
| result = a - b; | |
| break; | |
| case '*': | |
| result = a * b; | |
| break; | |
| case '/': | |
| result = (double)a / (double)b; | |
| break; | |
| default: | |
| cout << "Invalid operation. Program terminated." << endl; | |
| flag = 1; | |
| break; | |
| } | |
| if (0 == flag) | |
| { | |
| cout << result << endl; | |
| } | |
| } | |
| cout << "to continue: input two Integers(one space between them), then press Enter;" | |
| << endl << "to stop: press ctrl-C" << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment