/* * funcint3A.c */ #include int getanswer(void); // prototype: takes nothing, returns int float intaverage(int, int); // prototype: takes 3 int's, returns a float int intproduct(int,int); // prototype: takes 2 ints, returns 1 int int main(void) // header for function main: takes nothing, returns int { int aa, bb; // declare 2 ints float avrg; // declare float int prod; // declare 1 int do // execute block, then evalueat while befor second pass { puts("This program calculates the average, product of two integers.\n"); printf("Enter two integers separated by a space: "); scanf("%d%d", &aa, &bb); // read in 2 integers, // interpret as digits // assign to memory location of aa and bb getchar(); // fluch input buffer avrg=intaverage(aa,bb); // call function intaverage with value at aa and bb // assign result to avrg printf("\n\nThe average of %d and %d is %.2f.\n", aa, bb, avrg); prod=intproduct(aa,bb); // call function intproduct with value at aa and bb // assign result to prod printf("The product of %d and %d is %d.\n", aa, bb, prod); } while( getanswer() ); // call function getanswer, // if return value is 1, return to block return 0; } int getanswer(void) // header for function getanswer, takes nothing, returns int { char cc; // declare char printf("\nPress 'q' to quit, any other key to continue: "); // prompt for user input cc=getchar(); // read from stdin, assing one char to cc if ( cc=='q') // if char is q, { return 0; // reutrn 0 to calling fucntion } else { return 1; // return 1 to calling fruntion } } float intaverage(int xx, int yy) // header for function intaverage: // takes 2 ints, assigns to xx and yy // returns a float { return (xx+yy)/2.0; // add xx and yy, // divide result by 2.0 // Return the result to calling function } int intproduct(int xx, int yy) // header for function intproduct: // takes 2 ints, assigns to xx and yy // returns an int { return (xx*yy); // multiply xx by yy // return result to calling funxiton }