/* enterSales.c Author: Murray Saul Date: March 7, 2008 Purpose: Enter store # and corresponding sales amount into arrays via a function called enterData(), then in main, print the sales amounts for each store number */ #include #define SIZE 5 void enterData(double []); void clearInput(); main() { int x; double salesAmount[SIZE], total=0; enterData(salesAmount); printf ("\nMONTHY SALES REPORT (BY STORE NUMBER):\n\n"); for (x = 0; x < SIZE; x++) { printf ("Store #%-5d$%12.2lf\n", x + 1, salesAmount[x]); total += salesAmount[x]; } printf ("%-12s%11s\n", " ", "-------------"); printf ("%-12s$%12.2lf\n", "TOTAL", total); printf ("%-12s%11s\n", " ", "============="); } /* End of main program */ void enterData(double salesAmount[]) { int i, result; for (i = 0; i < SIZE; i++) { do { printf ("Enter sales amount for store #%d: ", i + 1); result = scanf("%lf", &salesAmount[i]); clearInput(); } while (( result != 1 ) && printf ("Invalid sales amount - ")); } } /* End of enterData() function */ void clearInput() { while ( getchar() != '\n' ) ; } /* End of clearInput() function */