# Absurd Math?!!

This is a discussion on Absurd Math?!! within the C Programming forums, part of the General Programming Boards category; Hello, It's has been a long time since my last post here (just saying). Anyway, here's my code: Code: double ...

1. ## Absurd Math?!!

Hello,
It's has been a long time since my last post here (just saying).
Anyway, here's my code:
Code:
```double i;
for(i = 0;i<1;i=i+0.1){
if(i*2 == 1.6)printf("%s\n", "Found the Number");
}```
If could spare a few minutes for me, and run the program, you'll notice, that the message doesn’t appear(even though 0.8, as you know, is the answer, and the 'for' loop definitely covers that number).
Any suggestions?
Thank you very much for your attention,
Thanks,
Daniel
P.S
I've tried the code in Java, Qbasic, and it's working perfectly on them...

2. Code:
`for(i = 0;i<1i+i0.1){`
Your program should give a error message
Code:
`for(i = 0;i<1;i+=0.1)`
Look u should compare the float with the == operator. search the form. And why this way

Code:
`printf("%s\n", "Found the Number");`
could me

Code:
`printf("Found the Number\n");`

ssharish2005

3. ## Didn't quite get that...

Could you correct the code please?
Thanks,
Daniel

4. Code:
```for(i=0; i<1; i += 0.1)
{
if(fabs(i*2- 1.6) < 0.00001)
printf("Found the Number\n");
}```
ssharish2005

5. you can search the forum, this was discussed many times... for example
Floating Values acting weird.

6. ## Working! XD Thanks :D!!!

Thank you very much again, it's working.
Thanks,
Daniel

Popular pages Recent additions