/* solution-2.c for exercise-2 demonstrates the following: - functions and prototypes - passing parameters - char * type for strings - scanf is a value returning function - if/else - exit() function */ #include #include #include void fatal( char * msg); /* fatal function prototype */ int main( ) { int inches; printf("Enter your height in inches (whole number): "); fflush(stdout); if (scanf("%d", &inches) != 1) fatal("scanf failed on coversion to integer\n"); if (inches <=0 ) fatal("inches must be greater than 0\n"); printf("\n%d' %d\"\n",inches/12,inches%12); return 0; } /* fatal function body */ void fatal( char * msg) { printf("\n%s\n",msg); exit( EXIT_FAILURE); }