You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Input two number and find the sum, difference, product and quotient using switch
#include<iostream>usingnamespacestd;classmaths {
public:int sum = 0, div, mul, sub;
int a, b;
char choice;
voidgetInput() {
cout << "Enter one number: ";
cin >> a;
cout << "Enter two number: ";
cin >> b;
}
voidgetChoice() {
cout << "Enter + for addition!" << endl;
cout << "Enter - for Substraction!" << endl;
cout << "Enter * for Multiplication!" << endl;
cout << "Enter / for Division!" << endl;
cin >> choice;
}
voidoperation() {
switch(choice) {
case'+': {
sum = a + b;
cout << "Sum is " << sum;
break;
};
case'-': {
sub = a - b;
cout << "Substraction is " << sub;
break;
};
case'*': {
mul = a * b;
cout << "Multiplication is " << mul;
break;
};
case'/': {
div = a / b;
cout << "Division is " << div;
break;
};
default: {
cout << "Invalid Input!";
break;
}
}
}
};
intmain() {
maths mt;
mt.getInput();
mt.getChoice();
mt.operation();
return0;
}
Output
> Enter one number: 10> Enter two number: 2 > Enter + for addition!> Enter - for Substraction!> Enter * for Multiplication!*> Enter / for Division!> 1> Sum is 12