Re: Strange code

From: Alex Fraser (me_at_privacy.net)
Date: 12/17/04


Date: Fri, 17 Dec 2004 00:43:33 -0000


"Ufit" <kot_tmp0SPAMSPAM@NOpoczta.fm> wrote in message
news:cpt887$og$1@news.onet.pl...
> double x;
> for(x=1; x<2; x=x+0.01)
> if (x==1.44) cout<<"ok";
>
> Why this doesn't work ?

Try this:

#include <cstdio>

int main(void) {
    double x;
    for (x = 1; x < 2; x = x + 0.01)
        std::printf("%.16f\n", x);
    return 0;
}

Alex