this is my code:
Code:
#include <iostream>
#include <cmath>
using namespace std;
double add()
{
double N1=0.0, N2=0.0, sum;
cout<<"Enter 2 numbers"<<endl;
cin>>N1>>N2;
sum=N1+N2;
return sum;
}//end of function add
double subtract()
{
double N1=0.0,N2=0.0, diff;
cout<<"Enter 2 numbers"<<endl;
cin>>N1>>N2;
diff=N1-N2;
return diff;
}//end of function subtract
double divide()
{
double N1=0.0,N2=0.0,ans;
cout<<"Enter 2 numbers"<<endl;
cin>>N1>>N2;
ans=N1/N2;
return ans;
}//end of function divide
double multiply()
{
double N1=0.0, N2=0.0,prod;
cout<<"Enter 2 numbers"<<endl;
cin>>N1>>N2;
prod=N1*N2;
return prod;
}//end of function multiply
void compare()
{
double N1=0.0,N2=0.0;
cout<<"Enter 2 numbers"<<endl;
cin>>N1>>N2;
if(N1>N2)
{
cout<<"The 1st number is larger"<<endl;
}
else if(N1<N2)
{
cout<<"The 2nd number is larger"<<endl;
}
else
{
cout<<"The numbers are equal"<<endl;
}
}//end of function compare
float sqrt()
{
float SQR=0.0;
cout<<"Enter the number"<<endl;
cin>>SQR;
SQR=sqrt(SQR);
cout<<"The answer is: "<<SQR<<endl;
return SQR;
}//end of square root function
double power()
{
double N1=0.0,N2=0.0,ans;
cout<<"Enter 2 numbers. The second number being the POWER."<<endl;
cin>>N1>>N2;
ans=pow(N1,N2);
cout<<endl<<"The answer is: "<<ans<<endl;
return ans;
}//end of function power
void menu()
{
int choice;
while(choice!=8)
{
cout<<"Please choose an operation"<<endl
<<"Press 1 Add"<<endl
<<"Press 2 Subtract"<<endl
<<"Press 3 Divide"<<endl
<<"Press 4 Multiply"<<endl
<<"Press 5 Compare"<<endl
<<"Press 6 Square root"<<endl
<<"Press 7 Power"<<endl
<<"Press 8 Quit"<<endl;
cin>>choice;
if(choice==1)
{
cout<<"The answer is:"<<add()<<endl;
}
else if (choice==2)
{
cout<<"The answer is:"<<subtract()<<endl;
}
else if(choice==3)
{
cout<<"The answer is:"<<divide()<<endl;
}
else if (choice==4)
{
cout<<"The answer is:"<<multiply()<<endl;
}
else if (choice==5)
{
compare();
}
else if (choice==6)
{
sqrt();
}
else if (choice==7)
{
power();
}
else
{
cout<<"Error in input data"<<endl;
}//end of if
}//end of while
if(choice==8)
{cout<<"Thank you for using my Calculator program."<<endl;}
}//end of menu function