-3
int main()
{
    float x = 50;
    float y = 1/x;
    float result = y * x;

    float test = 41;
    float z = 1/test;
    float testRes = z * test;


    while (result == 1)
    {    
        x--;
    }

    printf("%f\n", x);
    printf("%.6f\n", testRes);
}

My while loop is infinite, it never ends, but it should end at 41 because when I test 41, it equals 0.99999404

1 Answers1

3

result never changes within the loop, therefore there is no reason to believe that, once it starts, the loop will ever end.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358