Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#include<iostream>
#include<stdlib.h>
using namespace std;
//helper method that simulates a ball faced by batsman, returns the runs
//scored in that ball. returns -1 if the batsman is out
int faceBall(){
//generating a value between 1 and 100, representing a percentage
int i=(rand()%100)+1;
//finding the result based on value of i
if(i<=5){
//5% time - 6
return 6;
}else if(i<=8){
//3% time - 5
return 5;
}else if(i<=20){
//12% time - 4
return 4;
}else if(i<=25){
//5% time - 3
return 3;
}else if(i<=50){
//25% time - 2
return 2;
}else if(i<=80){
//30% time - 1
return 1;
}else if(i<=93){
//13% time - 0
return 0;
}else{
//7% time - out
return -1;
}
}
//method to perform the simulation
int simulate(){
//declaring number of sixes, fours, and balls to 0
int sixes=0, fours=0, balls=0;
int result;
//looping
do{
//facing a ball
result=faceBall();
//incrementing number of balls
balls++;
//if result is a 6, incrementing sixes
if(result==6){
sixes++;
}
//if result is a 4, incrementing fours
else if(result==4){
fours++;
}
//if result is a -1, batsman is out, returning the balls
else if(result==-1){
return balls;
}
}while(sixes<5 && fours<10); //until user hits 5 sixes OR 10 fours
return balls; //returning the balls faced
}
int main(){
//declaring total balls to 0
int total_balls=0;
//simulating for 5 times
for(int i=0;i<5;i++){
//adding number of balls needed to total balls
total_balls+=simulate();
}
//finding average balls needed and displaying it
double avg=(double)total_balls/5;
cout<<"An average of "<<avg<<" balls needed to score 5 sixes or 10 fours or get out"<<endl;
return 0;
}
/*OUTPUT*/
An average of 15.8 balls needed to score 5 sixes or 10 fours or get out
use basic c++ 3. In the game of cricket, based on his past statistics of play,...
Use basic C++
3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...
In a game of craps two dice are rolled and you can win or lose based on the sum of the numbers on the top faces of the dice. if the sum of the numbers on the top faces of the dice turns out to be 2 or 12, you can double your bet. what is the probability that the sum of the numbers on the top faces turns out to be 2 or 12? a 1/36 b 1/64 c...
Help me by guving a detailed solution.
Alice and Bob play an interactive game as follows. Alice is given 5 empty bags and an unlimited supply of balls of 6 different colors. Then they execute the following steps sequentially: (i) Bob selects a number bE 3,4) and tells it to Alice, (ii) Alice fills the five bags with balls and shows the bags to Bob, (iii) Bob selects b distinct colors and tells it to Alice (iv) Alice wins if...
ASSIGNMENT 5 – POWERBALL SIMULATION Powerball® is a combined large jackpot game and a cash game. Every Wednesday and Saturday night at 10:59 p.m. Eastern Time, we draw five white balls out of a drum with 69 balls (1-69) and one red ball out of a drum with 26 red balls (1-26). Draw sales cut off at least 59 minutes before the draw. Check for local cut-off time. Players win by matching one of the 9 Ways to Win. The...
3. In this question we simulate the rolling of a die. To do this we use the func- tion runif (1),which returns a randomnumber in the range (0,1). To get a random integer in the range (1,2,3,4,5,6), we use ceiling(6 runif (1)) or if you prefer, sarple(1:6,size-1) will do the same job. (a). Suppose that you are playing the gambling game of the Chevalier de Méré. That is, you are betting that you get at least one six in 4...
3. In this question we simulate the rolling of a die. To do this we use the func- tion runif (1),which returns a randomnumber in the range (0,1). To get a random integer in the range (1,2,3,4,5,6), we use ceiling(6 runif (1)) or if you prefer, sarple(1:6,size-1) will do the same job. (a). Suppose that you are playing the gambling game of the Chevalier de Méré. That is, you are betting that you get at least one six in 4...
In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...
The Powerball lottery is played twice each week in 44 states, the District of Columbia, and the Virgin Islands. To play Powerball, a participant must purchase a $2 ticket, select five numbers from the digits 1 through 69, and then select a Powerball number from the digits 1 through 26. To determine the winning numbers for each game, lottery officials draw 5 white balls out a drum of 69 white balls numbered 1 through 69 and 1 red ball out...