1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
//Francis Palagano
//10/09/2015
//Algorithm
//1 ask user to enter a simple A "+,-,*,/, or % " B equation.
//2 calculate equation
// 1 if problem contains +, calculate a+b= result
// 2 if problem contains -, calculate a-b = result
// 3 if problem contains /, calculate a/b
// 1 if a = 0, tell user divisor cannot be 0
// 4 if problem contains *, calculate a*b = result
// 5 if problem contains %, calculate a%b = result
// 1 if a = 0, tell user divisor cannot be 0
// 5 if problem does not contain stated above display invalid operation
//3 display results as a(operation)b=result
//4 end program
#include <iostream>
using namespace std;
int main()
{
int a, b, result;
char operation;
cout << " Please enter a simple mathmatical equation using +,-,*,/, or % : " ;
cin >> a >> operation >> b ;
switch(operation)
{
case '+':
result = a + b ;
break;
case '-':
result = a - b ;
break;
case '*':
result = a * b;
break;
case '/':
if ( a,b == 0 )
{ cout << "Divisor cannot be 0" << endl;}
else result = a / b;
break;
case '%':
if ( a,b == 0 )
{ cout << "Divisor cannot be 0" << endl; }
else result = a % b;
break;
default:
cout << "Invalid operation." << endl;
return -1;
}
cout << " The answer to your equation " << a << operation << b << "=" << result << endl;
system("pause");
return 0;
}
|