cmpflt.c 402 B

12345678910111213141516171819
  1. // cmpflt.c -- floating-point comparisons
  2. #include <math.h>
  3. #include <stdio.h>
  4. int main(void)
  5. {
  6. const double ANSWER = 3.14159;
  7. double response;
  8. printf("What is the value of pi?\n");
  9. scanf("%lf", &response);
  10. while (fabs(response - ANSWER) > 0.0001)
  11. {
  12. printf("Try again!\n");
  13. scanf("%lf", &response);
  14. }
  15. printf("Close enough!\n");
  16. return 0;
  17. }