In: Computer Science
Write a program that input two integer number and display results by performing the (+, -, ∗ , /) operations. It should check that divisor is not equal to zero? Secondly if user apply any operator other than that (+, -, ∗ , /) print error message? using if else (in C++)

#include <iostream>
using namespace std;
int main() {
int a, b;
char op;
cout << "Enter operator: ";
cin >> op;
cout << "Enter first number: ";
cin >> a;
cout << "Enter second number: ";
cin >> b;
if(op == '+') {
cout << "Result: " << (a + b) << endl;
}
else if(op == '-') {
cout << "Result: " << (a - b) << endl;
}
else if(op == '*') {
cout << "Result: " << (a * b) << endl;
}
else if(op == '/') {
if(b == 0) {
cout << "Divisor can not be zero" << endl;
} else {
cout << "Result: " << (a / b) << endl;
}
} else {
cout << "Invalid operator!\n";
}
}
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.