In: Computer Science
Welcome to the Bruins Goalie Saves Analysis This program will calculate the percentage of saves for a hockey goalie for 4 games after you have entered the games and saves for the goalie. Enter the number of goals for game #1: 3 Enter the number of saves for game #1: 22 The percent saves for game #1 is 88.0% Enter the number of goals for game #2: 4 Enter the number of saves for game #2: 33 The percent saves for game #2 is 89.2% Enter the number of goals for game #3: 1 Enter the number of saves for game #3: 16 The percent saves for game #3 is 94.1% Enter the number of goals for game #4: 0 Enter the number of saves for game #4: 22 The percent saves for game #4 is 100.0% The percent saves for 4 games for this goalie is 92.1% Thanks for using the Bruins Goalie Saves Analysis program.
Here is the C program for the above task:
#include <stdio.h>
int main() {
//print initial message on the console
printf("Welcome to the Goalie Saves Analysis\n");
printf("This program will calculate the percentage of saves for a hockey goalie for 4 games after you have entered the games and saves for the goalie\n");
//loop four times
int i;
for(i = 1; i <= 4; ++i) {
int goals, saves; //variables to store number of goals and saves
//input goals
printf("\nEnter the number of goals for game #%d: ", i);
scanf("%d", &goals);
//input saves
printf("Enter the number of saves for game #%d: ", i);
scanf("%d", &saves);
//calculate saves percent and print to screen upto 1 decimal place
float percent = ((float)saves / (goals + saves)) * 100;
printf("Enter the number of goals for game #%d: %.1f%%\n", i, percent);
}
printf("\nThanks for using the Bruins Goalie Saves Analysis program.\n");
return 0;
}
Sample IO: