OK this is what i did, thx to rags_to_riches
I got the choice print, but the result is still incorrect.
Code:
#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
void menu();
void fuc1(char);
void fuc2(char);
double calculate(char,double);
int main()
{
char x;
menu();
cout<<"Enter choice: ";
cin>>x;
if(x=='+'||x=='-'||x=='*'||x=='/'||x=='%'||x=='P'||x=='A'||x=='X')
fuc1(x);
else if(x=='R'||x=='F'||x=='T')
fuc2(x);
else
exit;
system("pause");
return 0;
}
void menu()
{
cout<<"+,-,*,/,%"<<endl;
cout<<"A\t averge"<<endl;
cout<<"X\t maximum"<<endl;
cout<<"P\t a^b"<<endl;
cout<<"R\t reciprocal"<<endl;
cout<<"F\t factorial"<<endl;
cout<<"T\t square root"<<endl;
cout<<"Q\t quit"<<endl;
}
void fuc1(char choice)
{
int operand1,operand2,result;
cout<<"Enter two values you want to calculate: ";
cin>>operand1 >>operand2;
if(choice=='+')
result=operand1+operand2;
if(choice=='-')
result=operand1-operand2;
if(choice=='*')
result=operand1*operand2;
if(choice=='/')
result=operand1/operand2;
if(choice=='%')
result=operand1%operand2;
if(choice=='P')
result=pow((double)operand1,(double)operand2);
if(choice=='A')
result=(operand1+operand2)/2;
else
if(operand1>operand2)
result=operand1;
else
result=operand2;
cout<<choice<<" "<<result<<" "<<operand1<<" "<<operand2<<endl;
}
void fuc2(char choice)
{
double operand1,result;
cout<<"Enter one value you want to calculate: ";
cin>>operand1;
calculate(choice,operand1);
cout<<choice<<" "<<result<<" "<<operand1<<endl;
}
double calculate(char choice,double x)
{
double result;
if(choice=='R')
result=1/x;
else if(choice=='F')
for(int i=1;i<=x;i++)
result*=i;
else
result=sqrt(x);
return result;
}