1

The code is below. When the variate i*dx is equal to 140, this would not meet the condition, but why cout works? if I changed the 1.4 to 1.3 or other numbers, this weird thing does not happen.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{   
    double dx = 0.01;
    float ip = 1.4;
    for(size_t i = 0; i < 200; ++i)
    {
        if(  (i*dx > ip)   &&   (abs(i*dx - ip) > 0)    &&   (i*dx < 1.6)  )
        {
            cout << "i = " << i << endl;
            cout << "i*dx = " << i*dx << endl;
            printf("printf. i*dx = %f \n", i*dx);   
            printf("printf. ip = %0.10f \n", ip);   
            break;
        }
    }
    return 0;
}

now, problem solved

0 Answers0