# Answer to Question #27710 in C++ for Mehmil Khan

Question #27710
Write a Simple Calculator Using If Else Statement that prompts the user to Input two Numbers. Then it will Display the Menu for Addition, Subtraction, Multiplication, Division, Square of 1st Number, Cube of 1st Number, Sin, Cos, Tan. After any choice it will Display the Answer
#include <conio.h>
#include <iostream>

using namespace std;

//main function
int main()
{
int choice=-1;//choice
float firstnumber;
float secondnumber;
cout<<"Enter fisrt number: ";
cin>>firstnumber;
cout<<"Enter second number: ";
cin>>secondnumber;
do{
";
cout<<"2 - Subtraction
";
cout<<"3 - Multiplication
";
cout<<"4 - Division
";
cout<<"5 - Square of 1st Number
";
cout<<"6 - Cube of 1st Number
";
cout<<"7 - Sin 1st Number
";
cout<<"8 - Cos 1st Number
";
cout<<"9 - Tan 1st Number
";
cout<<"0 - Exit";
cout<<"Select one item: ";
float result=0;//result variable
//Show result
if(choice==1){
result=firstnumber+secondnumber;
cout<<"
";//new line
}
if(choice==2){
result=firstnumber-secondnumber;
cout<<"Subtraction is: "<<result;//Subtraction
cout<<"
";//new line
}
if(choice==3){
result=firstnumber*secondnumber;
cout<<"Multiplication is: "<<result;//Multiplication
cout<<"
";//new line
}
if(choice==4){
result=firstnumber/secondnumber;
cout<<"Division is: "<<result;//Division
cout<<"
";//new line
}
if(choice==5){
result=firstnumber*firstnumber;
cout<<"Square 1st Number is: "<<result;//Square 1st
Number
cout<<"
";//new line
}
if(choice==6){
result=firstnumber*firstnumber*firstnumber;
cout<<"Cube 1st Number is: "<<result;//Cube 1st Number
cout<<"
";//new line
}
if(choice==7){
result=sin(firstnumber);
cout<<"Sin 1st Number is: "<<result;//Sin 1st Number
cout<<"
";//new line
}
if(choice==8){
result=cos(firstnumber);
cout<<"Cos 1st Number is: "<<result;//Cos 1st Number
cout<<"
";//new line
}
if(choice==9){
result=tan(firstnumber);
cout<<"Tan 1st Number is: "<<result;//Tan 1st Number
cout<<"
";//new line
}
}while(choice!=0);//exit if user enter 0

return 0;//return from function
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!