Ok I have been working on a basic calculator for C++. The only problem is that I don't know how to make it so if you divide by 0 it couts something. Anyone help. I know it would be possible with if/else statement. Heres the code so far.
#include <iostream>
using namespace std;
int main(){
cout << "Enter an Expression\n";
int first;
int second;
char function;
int answer;
while (cin >> first >> function >> second) {
switch (function) {
case '+': answer = first + second;
break;
case '-': answer = first - second;
break;
case '*': answer = first * second;
break;
case '/': answer = first / second;
break;
default : cout << "Only +, -, * or / allowed" << endl;
continue;
}
cout << "The Product is " << answer << endl << endl;
}
return 0;
}