/* * funcfloat.c * Project 2 * Chapter 8 * By John Stile * Purpose: convert funcint1.c to a progra that works with floats. * a) Copy funcint1.c to funcfloat.c * b) Rename the function get_int to get_float * c) Have the function get_float read in a float * d) Input 4 numbers * e) Compile */ #include float getint(void); // function prototype: takes nothing, returns int int main(void) // header for function main: takes nothing, returns int { float aa, bb, cc, dd; // declare 4 floats float avrg; // declare float puts("This program calculates the average of three integers.\n"); aa=getint(); // call funtion getint, assign to aa bb=getint(); // call funtion getin, assign to bb cc=getint(); // call funtion getin, assign to cc dd=getint(); // call funtion getin, assign to cc avrg=(float)(aa+bb+cc+dd)/4; // add aa, bb, and cc, // divide result by 3.0 // Assign to float avrg printf("The average of %f, %f, %f, and %f is %f.\n", aa,bb,cc,dd,avrg); // output result. return 0; // return 0 to calling program } float getint(void) { float ii; // declare int printf("Type an deciam number and press Enter: "); // prompt for input scanf("%f", &ii); // read from stdin // interpret as a digit // assign to memory location of ii getchar(); // clear input buffer return ((float)ii); // return value of ii to calling function }