Hi everyone,
I'm trying to code a calculator that performs the following operations:
+, -, /, *, %, ^, !, L
! factorial = x!
L log10= log10(x)
and im having trouble running the code because of the last three functions. I will post my code and I hope to get some help:
// Nawaf Alqahtani
// Oct 22, 2011
// Calculator Program
#include <iostream> // for cout, endl;
#include <cmath>
using namespace std;
int main()
{
char op;
int x=0;
int y=0;
int answer=0;
bool done = false;
bool error = false;
do
{
int x, y;
cout << ("Welcome to Calculator")<< endl;
cout << "Enter an operand: " << endl;
cin>> x;
cout << "Enter an operation: " << endl;
cin >> op;
//Select the operation ('Q' to quit);
//+, -, *, /, !,^, L, > !;
cout << "Enter an operand: " << endl;
cin >> y;
cout << "Enter Q to quit" << endl;
switch (op)
{
case '+':
cout << " The answer is " << x + y << endl;
break;
case '-':
cout << " The answer is " << x - y << endl;
break;
case '*':
cout << " The answer is " << x * y << endl;
break;
case '/':
cout << " The answer is " << x / y << endl;
break;
case '%':
cout << " The answer is " << x % y << endl;
break;
case '^':
cout << " The answer is " << ( pow( x, y)) << endl;
break;
case '!':
cout << "The answer is " << x! << endl;
break;
case 'L':
cout << " The answer is " << Log10(x) << endl;
break;
case 'Q' :
case 'q' :
done = true;
error = true;
break;
default: cout << " Invalid operator! " << endl;
error = true;
}
cout << " Thank you for using calculator program ";
cin >> op;
}
while (op == 'y');
return 0;
system ("pause");
return EXIT_SUCCESS;
}
Thank in advance