// passing.cpp - program to compute NFL passer ratings // Jim Plank // January, 2007 #include using namespace std; int main() { double attempts, completions, tyards, tds, interceptions; double cperc, crat; // Completion percentage and rating double yavg, yrat; // Yardage average and rating double tperc, trat; // Touchdown percentage and rating double iperc, irat; // Interception percentage and rating double rating; // Completion percentage and rating // Read in data cout << "Enter attempts, completions, total yards, tds, interceptions " ; cin >> attempts >> completions >> tyards >> tds >> interceptions; // Compute completion rating, which is (percentage-3)*0.05 cperc = completions / attempts * 100.0 ; crat = (cperc - 30.0) * 0.05; if (crat < 0.0) crat = 0; if (crat > 2.375) crat = 2.375; // Compute yardage rating, which is (avg_yardage-3)*.25 yavg = tyards / attempts ; yrat = (yavg - 3) * 0.25; if (yrat < 0.0) yrat = 0; if (yrat > 2.375) yrat = 2.375; // Compute touchdown rating, which is (TD_percentage)*.2 tperc = tds / attempts * 100.0 ; trat = (tperc) * 0.2; if (trat < 0.0) trat = 0; if (trat > 2.375) trat = 2.375; // Compute touchdown rating, which is 2.75-(Int)*.25 iperc = interceptions / attempts * 100.0 ; irat = 2.375 - iperc * 0.25; if (irat < 0.0) irat = 0; // Print out the individual ratings for testing purposes cout << crat << "\n"; cout << yrat << "\n"; cout << trat << "\n"; cout << irat << "\n"; // Compute overall ratings, which is the sum of the others, divided by 6, times 100 rating = ( crat + yrat + trat + irat ) / 6.0 * 100.0; cout << "Rating: " << rating << "\n"; }