Its C programming Answer the question The following is a par

Its C programming
Answer the question

The following is a part of a program that calculates an NFL Quarterback\'s Passer Rating.

#include <stdio.h>
#include <stdlib.h>

float passerRating(int completions, int attempts, int tds, int interceptions, int yards);
int getInt(char *prompt);   

int main(void)
{
int completions = 0, attempts = 0, tds = 0, interceptions = 0;
int yards = 0;
float rating = 0.0;
   
      while( 1 )
      {
            attempts = getInt(\"attempts\");
            if( attempts == 0 )
                  break;
            completions = getInt(\"completions\");
            tds = getInt(\"touchdowns\");
            interceptions = getInt(\"interceptions\");
            yards = getInt(\"yards\");

            rating = passerRating(completions, attempts, tds,
                                    interceptions, yards);
            printf(\"Rating is %.2f\ \", rating);
      }
      return 0;
}

int getInt(char *prompt)
{
char buffer[81] = {0};
int value = 0;

      printf(\"\ Enter %s: \", prompt);
      fgets(buffer, 81, stdin);
      value = atoi(buffer);
      return value;
}

Write the code for the passerRating function. The formula for the passer rating is:
a = (((completions / attempts) * 100) -30) / 20
b = ((tds / attempts) * 100) / 5
c = (9.5 - ((interceptions / attempts) * 100)) / 4
d = ((yards / attempts) - 3) / 4
If any of a, b, c or d are greater than 2.375, set that value to 2.375. Likewise, if any of a, b, c, or d are less than 0, set that value to 0.

passer rating = (a + b + c + d) / .06
Assume that the user\'s entries will adhere to the following rules:

completions <= attempts
tds <= completions
interceptions <= attempts
completions, tds, and interceptions are non-negative integers
attempts is a positive integer
yards is an integer
Replace a, b, c, and d with more meaningful variable names (they will be marked). Do not unnecessarily duplicate code in the passerRating function (i.e. replace duplicated code with a function).

No commenting is necessary (even function comments).

You do have to indent and brace correctly and consistently.

The next section is not necessary for answering the question but ...
If you\'re not familiar with football and you want to know about what these things are:

an attempt happens when a quarterback tries to throw the ball to a receiver
a completion happens when a receiver catches a pass attempt (this is good)
an interception happens when the opposing team catches a pass attempt (this is bad)
a TD happens when the receiver catches a pass attempt for a touchdown (this is really good)
yards indicates how far the pass completions went
For example, if a quarterback did the following:

pass attempt that was not caught
pass attempt that was not caught
pass attempt that was caught for 10 yards
pass attempt that was not caught
pass attempt that was caught for 30 yards
pass attempt that was intercepted
pass attempt that was caught for 50 yards and a touchdown
they would have 7 attempts, 3 completions, 1 interception, 90 yards, and 1 touchdown. This would give them a Passer Rating of 89.88.

Also, for example, if a quarterback threw 10 passes and only completed 1 for 10 yards, his Passer Rating would be 39.58

Solution

float passerRating(int completions, int attempts, int tds, int interceptions, int yards)
{
        float a,b,c,d,passer_rating;     
        float w=completions,x=attempts,y=tds,z=interceptions, v=yards;   
//because we are dividing these number and they are not containing floating number so we have to first store it in a float numbers.
        a = ((((w / x) * 100) -30) / 20);
        b = ((y / x) * 100) / 5;
        c = (9.5 - ((z / x) * 100)) / 4;
        d = ((v / x) - 3) / 4;
        if(a>2.375)
                a=2.375;
        if(a<0)
                a=0;
        if(b>2.375)
                b=2.375;
        if(b<0)
                b=0;
        if(c>2.375)
                c=2.375;
        if(c<0)
                c=0;              
        if(d>2.375)
                d=2.375;
        if(d<0)
                d=0;
        passer_rating = (a + b + c + d) / .06;
        return passer_rating;
}

Its C programming Answer the question The following is a part of a program that calculates an NFL Quarterback\'s Passer Rating. #include <stdio.h> #includ
Its C programming Answer the question The following is a part of a program that calculates an NFL Quarterback\'s Passer Rating. #include <stdio.h> #includ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site