#include <iostream>
#include <cmath>
usingnamespace std;
#define PI 3.14159265
int main()
{
double X, Y;
double resultPow, resultSin, resultCos;
char operation;
cout << "**********************************" << endl;
cout << "* 1 - Add *" << endl;
cout << "* 2 - Subtract *" << endl;
cout << "* 3 - Multiply *" << endl;
cout << "* 4 - Divide *" << endl;
cout << "* 5 - Raise X to the power Y *" << endl;
cout << "* 6 - Sine ( X ) *" << endl;
cout << "* 7 - Cosine ( X ) *" << endl;
cout << "* *" << endl;
cout << "* 0 - Quit *" << endl;
cout << "**********************************" << endl;
cout << "\n ENTER FIRST NUMBER : ";
cin >> X;
cout << "\n ENTER Option Number : ";
cin >> operation;
resultSin = sin (X*PI/180);
resultCos = cos (X*PI/180);
switch(operation)
{
case'1':
cout << "\n ENTER SECOND NUMBER : ";
cin >> Y;
cout << "\n The Result is " << "#### " << (X + Y) << " ####" << endl;
break;
case'2':
cout << "\n ENTER SECOND NUMBER : ";
cin >> Y;
cout << "\n The Result is " << "#### " << (X - Y) << " ####" << endl;
break;
case'3':
cout << "\n ENTER SECOND NUMBER : ";
cin >> Y;
cout << "\n The Result is " << "#### " << (X * Y) << " ####" << endl;
break;
case'4':
cout << "\n ENTER SECOND NUMBER : ";
cin >> Y;
cout << "\n The Result is " << "#### " << (X / Y) << " ####" << endl;
break;
case'5':
cout << "\n ENTER SECOND NUMBER : ";
cin >> Y;
resultPow = pow (X,Y);
cout << "\n ANSWER = " << "#### " << resultPow << " ####" << endl;
break;
case'6':
cout << "\n ANSWER = " << "#### " << resultSin << " ####" << endl;
break;
case'7':
cout << "\n ANSWER = " << "#### " << resultCos << " ####" << endl;
break;
case'0':
cout<< " are you sure you want to quit?" <<
cin.get();
}
return 0;
}
1. when i try the exponent option (5), it always gives me an answer of infinty.
2. I gotta do a while loop to keep it from closing without the user choosing the option to
3. Those "####"'s are supposed to be there. :)
1. it is because resuly pow is calculated after you input 'X' and 'Y' is a garbage memory address and then 'Y' is changed after and the calculation is not done again in the case 5.
you need to move the resultPow = Pow ( x,y) before the cout << ANSWER.... etc
2. on case 0;
add a
1 2 3 4 5
cout<< " are you sure you want to quit?" <<
cin.get();
}
return 0;
}
char play_again = 'y';
do
{
[code here]
cout << "Would you like to play again? (y or n)\n";
cin >> play_again;
if(play again = 'y')
{
continue;
}
else
{
break;
}
}while(play_again = 'y')
I don't see why you'd need the ####'s.
Happy coding.