Simple Calculator
#include<iostream>
using namespace std;
int main()
{
int value1, value2;
char action;
char choise;
do
{
cout<<"Enter two numbers : ";
cin>>value1 >>value2;
cout<<"Enter the operator + or - or * or / : ";
cin>>action;
switch(action)
{
case '+':
cout<<"The addition is : "<<value1 + value2<<endl;
break;
case '-':
cout<<"The subtraction is : "<<value1 - value2<<endl;
break;
case '*':
cout<<"The multiplication is : "<<value1 * value2<<endl;
break;
case '/':
cout<<"The division is : "<<value1 / value2<<endl;
break;
}
cout<<"Want to continue ? 'y' for YES 'n' if NO : ";
cin>>choise;
}while(choise=='y');
}
using namespace std;
int main()
{
int value1, value2;
char action;
char choise;
do
{
cout<<"Enter two numbers : ";
cin>>value1 >>value2;
cout<<"Enter the operator + or - or * or / : ";
cin>>action;
switch(action)
{
case '+':
cout<<"The addition is : "<<value1 + value2<<endl;
break;
case '-':
cout<<"The subtraction is : "<<value1 - value2<<endl;
break;
case '*':
cout<<"The multiplication is : "<<value1 * value2<<endl;
break;
case '/':
cout<<"The division is : "<<value1 / value2<<endl;
break;
}
cout<<"Want to continue ? 'y' for YES 'n' if NO : ";
cin>>choise;
}while(choise=='y');
}
Output :
Enter two numbers : 40 20
Enter the operator + or - or * or / : +
The addition is : 60
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 40 20
Enter the operator + or - or * or / : -
The subtraction is : 20
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 50 30
Enter the operator + or - or * or / : *
The multiplication is : 1500
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 60 30
Enter the operator + or - or * or / : /
The division is : 2
Enter the operator + or - or * or / : +
The addition is : 60
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 40 20
Enter the operator + or - or * or / : -
The subtraction is : 20
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 50 30
Enter the operator + or - or * or / : *
The multiplication is : 1500
Want to continue ? 'y' for YES 'n' if NO : y
Enter two numbers : 60 30
Enter the operator + or - or * or / : /
The division is : 2
1 Comments
This comment has been removed by a blog administrator.
ReplyDelete