answersLogoWhite

0


Best Answer

#include

#include

#include

using namespace std;

string ask(string prompt)

{

string input;

cout<

getline(cin, input);

return(input);

}

int ask_for_int(string prompt)

{

int input;

while(1)

{

string response = ask(prompt);

stringstream s(response);

if(s>>input)

return(input);

cout<<"Invalid input."<

}

}

int main()

{

cout<<"Slugging percentage calculator\n"<

while(1)

{

int at_bats = ask_for_int("How many at bats? ");

int singles = ask_for_int("How many singles? ");

int doubles = ask_for_int("How many doubles? ");

int triples = ask_for_int("How many triples? ");

int home_runs = ask_for_int("How many home runs? ");

int total_hits = singles + doubles + triples + home_runs;

if( total_hits <= at_bats )

{

double slg = ((double)( singles+(2*doubles)+(3*triples)+(4*home_runs)))/at_bats;

cout<<"\nSLG = "<

break;

}

cout<<"Invalid input.\nReason: the total hits exceeds the at bats."<

cout<<"Please re-enter data."<

}

}

Output

Slugging percentage calculator

How many at bats? 458

How many singles? 73

How many doubles? 36

How many triples? 9

How many home runs? 54

SLG = 0.847162

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program in C plus plus for slugging percentage?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you calculate On Base Plus Slugging percentage?

On base percentage plus slugging percentage


What is baseball's ops?

On base percentage Plus Slugging percentage.


How is OPS calculated?

OPS stands for 'on base percentage plus slugging percentage' and is equal to (on base percentage + slugging percentage). If a player's on base percentage is .350 and slugging percentage is .500, the OPS is .850.


What does OPS stand for in baseball stats?

On-Base Plus Slugging. So it is a combination of a players On-Base Percentage (OBP) and their Slugging Percentage (SLG). For example, if a player has a .448 OBP and a .613 SLG they would have an OPS of 1.061.


What does O P S mean in baseball?

On Base Percentage Plus Slugging Percentage


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Write a program in c plus plus to implement macro processor?

Don't write, it is already written, google for 'cpp'.


How do you write program to convert meter to kilometer in c plus plus?

Divide it by 1000.


Do I need to write a program to find a substring in a given string in c plus plus?

No.


What does OBPS mean in baseball stats?

OBP stands for On Base Percentage


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.