I can not get to make this comparison in this simple code error .. what kind I’m making and what is the reason? …
#include <stdio.h>
int main()
{
double a = 0.0;
double b = 1.0;
double c = 0.1;
while( a != b )
a=a+c;
printf("Suma hasta 1 completada\n");
}
Make it
while ( a <= b )Operations with double (and the datatypes itself) have problems with precision. So, avoid using double == double or double != double expressions. Rearrange them with < or >. Probably after the 10th iteration c is 1.00000 .. 001, instead of just 1. This is due mainly to the internal representation of double types.