Skip to content

Instantly share code, notes, and snippets.

@dd1994
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save dd1994/2a5c5bcbe00c53951abf to your computer and use it in GitHub Desktop.

Select an option

Save dd1994/2a5c5bcbe00c53951abf to your computer and use it in GitHub Desktop.
#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