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

#include <stdio.h>
#include <float.h>
#define CM_PER_FEET 30.48
#define CM_PER_INCH 2.54
double getHeight(void);
int main (void) {
double height;
height = getHeight();
while (height != 0) {
unsigned feet = height / CM_PER_FEET;
double inch = (height - feet * CM_PER_FEET) / CM_PER_INCH;
printf("%.2f cm = %u feet, %.1f inches\n", height, feet, inch);
height = getHeight();
}
printf("bye\n");
return 0;
}
double getHeight(void) {
double height;
printf("Enter a height in centimeters (<=0 to quit): ");
if (scanf("%lf", &height) != 1 || height <= 0) {
height = 0;
}
return height;
}