Question
Using the random dumber library in c++ please help me out with this problem. I am suppose to simulate at the bat using the information given.

Out Walk 9.7% Single 22.0% Double 6.1% Triple 2.5% Home Run 1.7% 58.0% Based on the above percentages, write a program to simulate Casey stepping up to the plate 1000 times and count and display the number of outs, walks, singles and so on. Then calculate and display his batting average: number of hits batting average- Times at bat - number of walks Hits singles doubles +triples + home runs Enclose your logic in a do while which will ask the user if he or she wishes to continue and accepts a char value of Y or N as an answer. Run and capture execution samples of at least two simulations.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Code:

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

int main()

{

              srand(time(0));

              //percentages

              double out, walk, s, d, t, hr;

              out = 58.0;

              walk = 9.7;

              s = 22.0;

              d = 6.1;

              t = 2.5;

              hr = 1.7;

             

              char choice; //to hold user choice

              do{

                             int atBat = rand()%1000 + 1; //times at bat 1 to 1000 times

                             //print all counts

                             cout<<"No. of Outs: "<<(out*atBat)/100<<endl;

                             cout<<"No. of Walks: "<<(walk*atBat)/100<<endl;

                             cout<<"No. of Singles: "<<(s*atBat)/100<<endl;

                             cout<<"No. of Doubles: "<<(d*atBat)/100<<endl;

                             cout<<"No. of Triples: "<<(t*atBat)/100<<endl;

                             cout<<"No. of Home Runs: "<<(hr*atBat)/100<<endl;

                             //calculate batting average

                             double avg = ((s+d+t+hr)*atBat)/(100*(atBat - (out*atBat)/100));

                             cout<<"Batting average: "<<avg*100<<endl; //print avg

                            

                             //get user choice

                             cout<<endl<<"Do you want to continue? (Y/N): ";

                             cin>>choice;

              }while(choice == 'y'||choice == 'Y');

             

              return 0;

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Using the random dumber library in c++ please help me out with this problem. I am...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

  • Please read case article, "Attention Kmart Shoppers? Into and out of Bankruptcy" and help me come...

    Please read case article, "Attention Kmart Shoppers? Into and out of Bankruptcy" and help me come up with a solution for the case as well as action steps to implement the solution! Thank you!! ATTENTION KMART SHOPPERS? Former Kmart CEO, Charles C. Conaway, failed in his 19-month effort to revive the iconic firm, resulting in the largest retailing bankruptcy filing in history on January 22, 2002 (Davies, et al., 2002). On March 11, 2002, bankrupt Kmart named James B. Adamson...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT