# Math Division Problem

• 06-12-2007
Math Division Problem
I will put the code in first! I will not pu the whole code as it takes too much space! I will just put the thing that I need help on!
Code:

```else if (choice == 4)     {     printf ("You chose division!\n\n");     printf ("Input the first integer,x:\n");     scanf ("%d", &x);     printf ("Input the second integer, y:\n");     scanf ("%d", &y);     printf ("The result is:%d\n", x / y);     }```
If I do not put in soem decimals like 10 and 5 or 30 and 10 or something that divides proper, I would give me some crazy results! I tried floating point with %f instead of %d and defined x and y as float also and it gives me -o.something different all the time!

What is the mistake or what do I need to do to make it work properly?

BTW, I tried the % operator instead of / division too, then it gives me plain 0!
• 06-12-2007
Dave_Sinkula
Quote:

What is the mistake or what do I need to do to make it work properly?

If you expect a floating point result, use floating point rather than integers. Integer math is not the same as floating point math.
• 06-12-2007
vart
Could you show your "crazy results"?
like 5/2 == 2
or 17 / 3 = 5
?

And also your code using floats could be of some interest. Post it too.
• 06-12-2007
ulillillia
Integer division - 9/5 doesn't mean 1.8 or 2, it means 1. Even to a float, double, or 1 million-bit floating point variable, it doesn't mean exactly 1.8. That's the thing with division.
• 06-13-2007