Divide by zero prevention squad

Hi,

I am making a program to do some simple math.

everything works fine, Addition, Subtraction, Multiplication, and (kinda) Division.

My problem is:

I want to be able to detect if someone is trying to divide by zero, and, if true, move them to an entirely different part of the program.

How does one go about doing this?

Another problem I'm having with the division, is decimal places, it seems to round to the nearest 1, how can i make it round to the nearest, say, thousandth?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

     int number13, number14;
     int answer5;
     
     
     cout << "number 1? ";
     cin >> number13;
     cout << "number 2? ";
     cin >> number14; //If this =0, redirect to another part of the program (that will yell at the user for doing so)
     
     answer5 = number13 / number14;
     cout << "\nAnswer is " <<  answer5;
     printf("\n");
     printf("\n");





Thanks,
Stephen
Integers can only store integer numbers (makes sense, right?). Hence the rounding. Use floats or doubles if you don't want that.
As for redirecting, it is difficult to say. Maybe throw something;?
Maybe an if or an if/else statement?
That really depends on what you want to do. If it's just "invalid input! enter another number!", if/else (and a little bit of while) would do.
That's pretty much what i want to do, but I'm not exactly sure how to do it (is a noob)

Can you help?
Thanks!!!!
Topic archived. No new replies allowed.