# Thread: float value returning: 1.#INF

1. ## float value returning: 1.#INF

Code:
```{

float MPH, hours;
int Miles;

Miles = 37 + ((15000/5280) + (12000/YARDS_IN_MILES));

hours = 45/60;
MPH = Miles/hours;

cout << "MPH: " << MPH;
return MPH;

}```
MPH couts 1.#INF -- not sure why... even if I use setprecision. Any ideas?

2. Well: hours is set to 0.0 (since 45/60 is 0 remainder 45, and remainder don't count); and dividing by 0.0 gives 1.#INF, since the fancy infinity sign is hard to print.

In other words: do hours = 45.0/60.0; instead.

3. The result of this expression - dividing an integer 45 by an integer 60 yields zero. Then, you divide Miles by zero.

Todd

4. Originally Posted by Todd Burch
The result of this expression - dividing an integer 45 by an integer 60 yields zero. Then, you divide Miles by zero.

Todd
Also, 15000/5280 is equal to 2, as far as the compiler is concerned.

5. And as a metric user, I have no idea what YARDS_IN_MILES is, but if it's a integer, too, there's another bad calculation.

6. Originally Posted by lord
Code:
```{

float MPH, hours;
int Miles;

metric conversion = 37 + ((15000/5280) + (12000/YARDS_IN_MILES));

hours = 45/60;
MPH = Miles/hours;

cout << "MPH: " << MPH;
return MPH;

}```
MPH couts 1.#INF -- not sure why... even if I use setprecision. Any ideas?
I;m looking into this.

7. This thread has been dormant for over 3 months. If the OP still had the problem, he'd have posted.