// Programmer: Dr. McVey // Date: January 31, 2008 // Purpose: This programs calculates the total points and shooting // percentage for 3pt, 2pt, and free throws for a single player. // // This program illustrates the use of a variable to accumulate // a total. It also illustrates the ability to reuse variables, // in this case shots_taken, shots_made and percentage. // Input: all input comes from keyboard // Output: all output is written to the console window // Assisted By: csci 110 students #include #include using namespace std; int main() { string FName, LName; int shots_taken, shots_made; double percentage; int TotalPoints; // Read name cout << "Enter Firstname and last name: "; cin >> FName >> LName; cout << FName << ' ' << LName << endl; // Do 3-pt information cout << "enter 3pt shots taken: "; cin >> shots_taken; cout << "enter 3pt shots made: "; cin >> shots_made; cout << shots_taken << " " << shots_made << endl; percentage = double(shots_made) / shots_taken * 100; cout << "3 pt Percentage: " << percentage << "%" << endl; TotalPoints = 3 * shots_made; //cout << "Points so far: " << TotalPoints << endl; // Do 2-pt information cout << "enter 2pt shots taken: "; cin >> shots_taken; cout << "enter 2pt shots made: "; cin >> shots_made; cout << shots_taken << " " << shots_made << endl; percentage = double(shots_made) / shots_taken * 100; cout << "2 pt Percentage: " << percentage << "%" << endl; TotalPoints = TotalPoints + 2 * shots_made; // TotalPoints is an ACCUMULATOR //cout << "Points so far: " << TotalPoints << endl; // Do 1-pt information cout << "enter free throws taken: "; cin >> shots_taken; cout << "enter free throws made: "; cin >> shots_made; cout << shots_taken << " " << shots_made << endl; percentage = double(shots_made) / shots_taken * 100; cout << "Free Throw Percentage: " << percentage << "%" << endl; TotalPoints = TotalPoints + shots_made; // TotalPoints is an ACCUMULATOR cout << "Points so far: " << TotalPoints << endl; return 0; }