Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
642 B

  1. #include <stdio.h>
  2. #include <float.h>
  3. #define CM_PER_FEET 30.48
  4. #define CM_PER_INCH 2.54
  5. double getHeight(void);
  6. int main (void) {
  7. double height;
  8. height = getHeight();
  9. while (height != 0) {
  10. unsigned feet = height / CM_PER_FEET;
  11. double inch = (height - feet * CM_PER_FEET) / CM_PER_INCH;
  12. printf("%.2f cm = %u feet, %.1f inches\n", height, feet, inch);
  13. height = getHeight();
  14. }
  15. printf("bye\n");
  16. return 0;
  17. }
  18. double getHeight(void) {
  19. double height;
  20. printf("Enter a height in centimeters (<=0 to quit): ");
  21. if (scanf("%lf", &height) != 1 || height <= 0) {
  22. height = 0;
  23. }
  24. return height;
  25. }