/* Program file: snowhp3.c Author: Harmonie Snow Date: October 9, 2022 Assignment: Program #3 Objective: This program calculates and prints the average of two or more movie rating values entered by the user. */ #include #include #include int main(void) { /*declare variables*/ int num_rate, rating = 0, rate_sum = 0, x = 1; char c; float movie_av; /*greet the user*/ printf("Welcome to Mr. Paw's Movie Rating Analyzer.\n\n"); /*explain the program*/ printf("This program calculates the average of as many movie ratings you wish to enter..\n\n"); /*prompt the user for # of movie ratings to process.*/ do { printf("First, enter the number of movie ratings to process: "); scanf("%i", &num_rate); while ( (c = getchar() != '\n') && c != EOF); if ( num_rate < 2 ) printf("Sorry, we need at least two ratings to provide an average. Try again.\n\n"); } while (num_rate < 2); /*end loop*/ /*prompt the user for each movie rating, one by one.*/ do { printf("Enter movie rating #%i: ",x); scanf("%i", &rating); while ( (c = getchar() != '\n') && c != EOF); if ( rating >= 0 && rating <= 10 ) { x = x + 1; rate_sum = rate_sum + rating; printf("Cool. The sum is %i now.\n",rate_sum); } else { printf("Sorry, the rating must be between 0 and 10.\n"); } } while (x <= num_rate); /*end loop*/ /*once all values are entered, calculate the average of all the valid values.*/ movie_av = rate_sum / num_rate; printf("The average of the %i movie ratings entered is %.1f stars.\n\n", num_rate, movie_av); /*display to the user a message based on the average found.*/ if ( movie_av < 2.5 ) printf("You are a tough critic!\n"); else if ( movie_av >= 2.5 && movie_av < 5.5 ) printf("Your movie ratings are pretty low.\n"); else if ( movie_av >= 5.5 && movie_av < 8.5 ) printf("Your movie ratings are fair.\n"); else if( movie_av >= 8.5 ) printf("You are a very generous critic!\n"); } /*end main*/