#include <iostream>
using namespace std;
int main()
{
double firstNo;// first number is stored here
double secondNo;
double result;//variable for result when first and second number are operated upon
char operation;// place to store the user's inputed operation
// asks the user to choose the first number
cout<< "Enter in the first Number ->";
cin >> firstNo;
// asks the user for the second number
cout<< "Enter in the second Number -> ";
cin >> secondNo;
// asks the user for an operation to preform
cout<< "which operation would you like to choose?\n";
cout<< "(+) add, (-) sub, (*)multiply, (/) divide";
cin >> operation;
// if else statements that determine which operation is going to be preformed on numbers'
if (operation == '+'){
result = firstNo + secondNo;
cout<< "The sum of these two numbers are ->" << result << "\n";
}
else if (operation == '-'){
result = firstNo - secondNo;
cout<< "The difference of these two numbers are ->" << result << "\n";
}
else if (operation == '*'){
result = firstNo * secondNo;
cout<< "The product of these two numbers are ->" <<result << "\n";
}
else {
result = firstNo / secondNo;
cout<< " The quotient of these two numbers are ->" << result << "\n";
}
cout<<"/n";
return 0;
}
I need to catch a division by zero so i can tell the user "you cannot divide by zero" instead of using if then statements i was wondering how may i go about this using a try- catch statement?