1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
using namespace std;
int main( )
{
double batting_average, at_bats, hits, singles, doubles, triples, homeruns, slugging_percentage, walks, hit_by_pitch, sacrifice_flies;
double on_base_percentage, OPS, player_name;
std::cout.precision(3);
{
cout << "What's the player's name? ";
cin >> player_name;
cout << "How many at bats has the player had? ";
cin >> at_bats;
cout << "How many hits has the player had? ";
cin >> hits;
batting_average = (hits / at_bats);
cout << player_name << "'s batting average is, " << batting_average << ".\n";
cout << endl;
cout << "How many singles has the player hit? ";
cin >> singles;
cout << "How many doubles has the player hit? ";
cin >> doubles;
cout << "How many triples has the player hit? ";
cin >> triples;
cout << "How many homeruns has the player hit? ";
cin >> homeruns;
slugging_percentage = ((singles) + (2 * doubles) + (3 * triples) + (4 * homeruns)) / at_bats;
cout << player_name << "'s slugging percentage is, " << slugging_percentage << ".\n";
cout << endl;
cout << "How many walks does the player have? ";
cin >> walks;
cout << "How many hit by pitches does the player have? ";
cin >> hit_by_pitch;
cout << "How many sacrifice flies does the player have? ";
cin >> sacrifice_flies;
on_base_percentage = (hits + walks + hit_by_pitch) / (at_bats + walks + hit_by_pitch + sacrifice_flies);
cout << player_name << "'s on-base percentage is, " << on_base_percentage << ".\n";
cout << endl;
OPS = on_base_percentage + slugging_percentage;
cout << player_name << "'s OPS (On-Base + Slugging) is, " << OPS << ".\n";
}
return 0;
}
|