Question: Write a C program that determines the batting averages for 4 baseball players. We will explain to the user very clearly what the program will
Write a C program that determines the batting averages for 4 baseball players. We will explain to the user very clearly what the program will be doing and how they should enter data.
The program should prompt the user to enter the number of at bats and the number of hits for each of the 4 baseball players. The program should then calculate and display the average obtained for each baseball players. Once processing is complete for the 4 baseball players, the program will calculate the overall average (total hits / total number of at bats) and display a friendly exit message as shown below.
Welcome to the Red Sox batting Analysis
This program will calculate the average for 4 Red Sox baseball players after you have entered the at bats and hits for each player.
Enter the number of at bats for baseball player #1: 9
Enter the number of hits for baseball player #1: 3
*** The batting average for baseball player #1 is 0.333
Enter the number of at bats for baseball player #2: 5
Enter the number of hits for baseball player #2: 2
*** The batting average for baseball player #2 is 0.400
Enter the number of at bats for baseball player #3: 6
Enter the number of hits for baseball player #3: 1
*** The batting average for baseball player #3 is 0.167
Enter the number of at bats for baseball player #4: 5
Enter the number of hits for baseball player #4: 5
*** The batting average for baseball player #4 is 1.000
*** The overall running batting average for the Red Sox is 0.440 Thanks for using the Red Sox batting Analysis program.
The bold blue text represents the "output" from your program. Also note that what the user types in is indicated by the bold black letters within the blue area above. The exact output spacing is important.
Use 5 variables of type int, and 1 of type float, and 1 of type char
(for the buffer clearing statement required).
This program requires an introductory statement to the user.
This program requires a loop structure (a for loop is best, or while or do.
The loop requires 3 printf statements: 1 to prompt the user for the "number of at bats"; 1 to prompt for "number of hits"; and a third to display the calculated "batting average for each baseball player".
The loop also requires 2 scanf statements: 1 to "read in" the number of at bats which is input by the user; and a second to "read in" the hits for each baseball player, which is also input by the user; and two buffer clearing statemnts.
This program requires 3 calculations within the loop - one for the current players average, and two accumulators to add up the total at bats and total hits for the final calculation.
This program requires another printf statement (outside the for loop) to display the average for all players.
The loop index should be used to display the current baseball player calculation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
