I need to create an error message when a number is divided by 0. How would i go about doing that
Code:#include <iostream> using namespace std; int main () { // Variable Declarations int num1, num2, num3, num4; char letter = 'y', symbol; // Prompt cout << "This Program will add, subtract, multiply, and divide" << "the two numbers you enter." << endl; cout << endl; while (letter == 'y') { cout << "Please enter two numbers: "; cin >> num1 >> num2; cout << endl; cout << "Please input the operation you would like to use: "; cin >> symbol; cout << endl; if (symbol == '+') { num3 = num1 + num2; cout << "The sum is: " << num3 << endl; } else if (symbol == '-') { num3 = num1 - num2; cout << "The difference is: " << num3 << endl; } else if (symbol == '*') { num3 = num1 * num2; cout << "The product is: " << num3 << endl; } else if (symbol == '/') { num3 = num1 / num2; num4 = num1 % num2; cout << "The quiotient is: " << num3 << " The remainder is: " << num4 << endl; } else cout << "Invalid symbol." << endl; cout << "Would you like to run the program again [y/n] "; cin >> letter; cout << endl; } cout << "End of Program" << endl; return 0; }



LinkBack URL
About LinkBacks


