Question

Write a C program that calculates the percent saves for a soccer goalie for 4 games...

Write a C program that calculates the percent saves for a soccer goalie for 4 games and the overall percentage of saves which is saves divided by the sum of goals plus saves

* In this program I used 4 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).

* The loop requires 3 printf statements: 1 to prompt the user for the "number of goals"; 1 to prompt for "number of saves"; and a third to display the calculated "percent saves".

* The loop also requires 2 scanf statements, and two buffer clearing statements.

* This program requires 3 calculations within the loop - one for the game percent saves, and two accumulators to add up the total saves and total goals for the final calculation.

* This program requires another printf statement (outside the for loop) to display the percent saves for all games.

* The loop index should be used to display the current game calculation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

#include<stdio.h>
void main()
{
   int goals[4],saves[4],totalsaves=0,totalgoals=0,i;
   float savespercent,totalsavespercent;

   printf("This program calculates overall percentage of saves by a soccer goalie\n");
   for(i=0;i<4;i++)
   {
       printf("\nEnter number of goals in match %d:",i+1);
       scanf("%d",&goals[i]);
       printf("Enter number of saves in match %d:",i+1);
       scanf("%d",&saves[i]);
       savespercent=(float)saves[i]/(float)goals[i];
       savespercent=savespercent*100.00;
       printf("\nPercentage of saves in match %d is %.2f",i+1,savespercent);
       totalsaves=totalsaves+saves[i];
       totalgoals=totalgoals+goals[i];
   }
   totalsavespercent=(float)totalsaves/(float)totalgoals;
   totalsavespercent=totalsavespercent*100.00;
   printf("\nTotal Percentage of saves in all matches is %.2f\n",totalsavespercent);
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a C program that calculates the percent saves for a soccer goalie for 4 games...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program Description Write a program that calculates the distance between two places on Earth, based on...

    Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...

  • I'm trying to write a program in C that calculates the area of a rectangle. I...

    I'm trying to write a program in C that calculates the area of a rectangle. I need to have a function that gets dimensions from a user and stores them with pointers and addresses and another function that calculates the area... my question is how do i access that values from the dimension function so that I can use it in my calculation and main function.. for example. void userDimensions(float *base, float *height){ scanf("%lf" , base); scanf("%lf", height); } float...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • C++ program by using while loop structure. Write an interactive program (C++) to prompt and read...

    C++ program by using while loop structure. Write an interactive program (C++) to prompt and read two float type numbers, Then your program should perform and print the following arithmetic: (use while loop structure to repeat program 2 times. 1) Sum 2)Difference 3) Product 4) Quotient 5) Modulus (use system defined fmod function) You must use system's defined function prototype and/or to create programmer's defined function prototype for each of the above calculation. In addition, create a function called "DISPLAYLINE...

  • C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...

    C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings to double values. Calculate the sum,difference,and product of these values and print them. int main(){    // character string value array for user    char stringValue[10];       double sum=0.0;// initialize sum to store the results from 2 double values       double difference=0.0; // initialize difference to store the results from 2 double values       double product = 0.0; // intitialzie product...

  • Write a program in C language that lets a user manipulate bits individually in a 4-byte...

    Write a program in C language that lets a user manipulate bits individually in a 4-byte variable. The program should begin with all bits having a value of zero. The program should enter a loop where it prints out the current bit values as a single integer using the twos complement bit model. It should then prompt the user to either set a bit, clear a bit, or exit. If the user desires to set a bit or clear a...

  • For C# The manager of an event venue wants you to write a program that calculates...

    For C# The manager of an event venue wants you to write a program that calculates the total ticket sales after each event. There are four types of tickets: orchestra ($100) floor ($75) tier 1 ($50) tier 2 ($40) tier 3 ($35) The user should be asked for what level do they have tickets and how many. Please note: this program should only accept one type of ticket. After each event, data is input by the user and then displayed...

  • Write a C program that does the following: Displays a menu (similar to what you see...

    Write a C program that does the following: Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square,Diamond (with selected height and selected symbol), or Quits if user entered Q.Apart from these 2 other shapes, add a new shape of your choice for any related character. Program then prompts the user to enter a number and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT