Make a simple calculator using switch statement. Use 4 mathematical operations in
mathematics.
a. When you type A in the console, it will add two numbers
1
st number: 198
2
nd number: 196
b. When you type S, it will subtract two numbers.
1
st number: 145
2
nd number: 67
c. When you type D, it will divide two numbers.
1
st number: 256
2
nd number: 8
d. When you type M, it will multiply two numbers.
1
st number: 125
2
nd number: 5
#include <iostream>
using namespace std;
int main()
{
char size;
int Number_1,Number_2,result;
cout << "THis is a simple calculator" << endl;
cout<<"Make the choice"<<endl;
cin>>size;
switch (size){
case 'A':
Number_1=198,Number_2=196;
result=Number_1+Number_2;
cout<<"Result is: " <<result;
break;
case 'S':
Number_1=145,Number_2=67;
result=Number_1-Number_2;
cout<<"Result is: " <<result;
break;
case 'D':
Number_1=256,Number_2=8;
result=Number_1/Number_2;
cout<<"Result is: " <<result;
break;
case 'M':
Number_1=125,Number_2=5;
result=Number_1*Number_2;
cout<<"Result is: " <<result;
break;
}
return 0;
}
Comments
Leave a comment