#include #define MAX_WARMUPS 5 void print_warmups(double warmups[], int num_warmups); int main(void) { //declare array double warmups[MAX_WARMUPS]; //declare variable to hold number of warmups entered int num_warmups = 0; //declare variable to hold answer to user response char answer; //prompt user printf("Would you like to enter a warmup score (y or n)?"); scanf("%c", &answer); fflush(stdin); //new code -- takes the place of reading 2 chars //verify answer was y or n while(answer != 'y' && answer != 'n') { printf("Bad answer. Try again."); scanf("%c", &answer); fflush(stdin); } //as long as the answer was y and the array is not full while((answer == 'y' || answer == 'Y') && (num_warmups < MAX_WARMUPS)) { //prompt for score printf("Enter score: "); //store in next element of array scanf("%lf", &warmups[num_warmups]); //add one to the number of warmups entered num_warmups++; fflush(stdin); //if the array is not full -- prompt the user if(num_warmups < MAX_WARMUPS) { printf("Would you like to enter anoter warmup score?"); scanf("%c", &answer); fflush(stdin); } else { //the array is full so print a message and end the loop printf("Maximum number of warmups reached.\n"); break; } //verify answer was y or n while(answer != 'y' && answer != 'n') { printf("Bad answer. Try again."); scanf("%c", &answer); fflush(stdin); } } //call function to print array of scores //pass in array AND the number of elements stored in the array print_warmups(warmups, num_warmups); return(0); } /** * Name: print_warmups * Description: This function prints out all warmup scores that were stored in the array. * Requires: A pointer to the array of doubles and a integer which represents the number * of doubles actually stored in the array. * Returns: Nothing * Side effects: Prints all values in the array. */ void print_warmups(double warmups[], int num_warmups) { int i; //for each element in the array for(i = 0; i < num_warmups; i++) { //print that element printf("Next Score: %lf\n", warmups[i]); } }