# Need quick help

• 02-22-2006
Surfndog
Need quick help
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; }```
• 02-22-2006
Dae
Code:

```else if (symbol == '/') { if(num2 == 0) cout << "error" << endl;```
I think.
• 02-22-2006
wildex999
Well, it would be wrong if 0/10 too, so check both numbers:

Code:

```else if (symbol == '/') { if(num2 == 0 || num1==0 ) cout << "error" << endl;```
• 02-22-2006
Xipher
Quote:

Originally Posted by wildex999
Well, it would be wrong if 0/10 too, so check both numbers:

Code:

```else if (symbol == '/') { if(num2 == 0 || num1==0 ) cout << "error" << endl;```

umm, 0/10 = 0, and is perfectly legal in mathimatics

10/0 == ERRRRRRRRRRR
• 02-22-2006
wildex999
Damn, need to check my math skills again -_-'