/* enterSales.c Author: Murray Saul Date: March 11, 2008 Purpose: To demonstrate use of arrays in functions */ #include #define SIZE 5 void clearInput(); void enterData(double x[]); main() { double monthlySalesAmount[SIZE], total = 0.0; int i; enterData(monthlySalesAmount); printf ("\nMONTHY SALES REPORT (BY STORE NUMBER):\n\n"); for ( i = 0; i < SIZE; i ++) { printf ("Store #%-12d$%10.2lf\n", i + 1, monthlySalesAmount[i]); total += monthlySalesAmount[i]; } printf ("%25s\n", "-------------"); printf ("%-12s$%12.2lf\n", "TOTAL", total); printf ("%25s\n", "============="); } /* End of main program */ void clearInput() { while (getchar() != '\n') ; } /* End of clearInput() */ void enterData(double x[]) { int j, returnValue; for (j = 0; j < SIZE; j++) { do { printf ("Enter sales amount for store #%d: ", j + 1); returnValue = scanf ("%lf", &x[j]); clearInput(); } while (( returnValue != 1) && printf ("Invalid Amount - ")); } /* Close outter loop */ } /* End of enterData() function */