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;
char s;
int a, b;
int main()
{
cin >> s >> a >> b;
switch (s)
{
case 'A':
cout << a+b << '\n';
break;
case 'S':
cout << a-b << '\n';
break;
case 'D':
cout << a/b << '\n';
break;
case 'M':
cout << a*b << '\n';
break;
default:
break;
}
return 0;
}
Comments
Leave a comment