Question

I need to submit a program immediately and am seeking for instant help for now. Can...

I need to submit a program immediately and am seeking for instant help for now. Can anybody please give me a code for this question?

C++ Write a program to simulate rolling a six-sided fair die. Allow the user to enter the number of rolls.Your program should use rand() to get the result of die rolling.Compute the number of occurrences for each number roll.Calculate the percentage for each number roll.Out put the results in the following format.Use a do while loop to allow the user to repeat the process.Write atleast two (user defined) functions that return a value.Here is the sample run for your program:

Please enter the number of die rolls:25

Number Frequency Percentage

1 3 0.12

2 6 0.24

3 10 0.40

4 1 0.04

5 3 0.12

6 2 0.08

Do you want to continue rolling die another time? Press Y or N: Y

Please enter the number of die rolls: 100

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<iomanip>
using namespace std;
int random()
{
return rand()%6+1;
}
char getChoice()
{
char ch;
cout<<"Do you want to continue rolling die another time? Press Y or N: ";
cin>>ch;
return ch;
}
int main()
{
char ch;
do
{
int number_of_rolls;
srand(time(NULL));
int a[6] = {0 };
cout <<"Please enter the number of die rolls: ";
cin >> number_of_rolls;
cout << endl;
for(int i=0; i<number_of_rolls; i++){
int value = random();
a[value-1]++;
}
cout<<fixed;
cout<<"Number\tFrequency\tPercentage"<<endl;
for(int i=0; i<6; i++)
cout <<(i+1) <<"\t" << a[i] << "\t\t" <<setprecision(2)<< (double)(a[i])/number_of_rolls << endl;
ch=getChoice();
}while(ch=='y'||ch=='Y');
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I need to submit a program immediately and am seeking for instant help for now. Can...
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
  • Needs to be done in visual studio. I keep having problems with making my own function...

    Needs to be done in visual studio. I keep having problems with making my own function to call for the statistics and the random number generator. they are both supposed to be separate functions from the main. Can anyone help? Language is C Overview: This third programming assignment will be the first to require the use of arrays. Like the second program, this program will be modular and make use of functions (including, this time, functions which process arrays). Brief...

  • Random Number Generation and Static Methods Write a program that simulates the flipping of a coin...

    Random Number Generation and Static Methods Write a program that simulates the flipping of a coin n-times to see how often it comes up heads or tails. Ask the user to type in the number of flips (n) and print out the number of times the coin lands on head and tail. Use the method ‘random()’ from the Math class to generate the random numbers, and assume that a number less than 0.5 represents a tail, and a number bigger...

  • Please Help! I need to update the code below to meet these criteria! 1. The constructor...

    Please Help! I need to update the code below to meet these criteria! 1. The constructor of die class initializes face of Die to 3 2. roll method updates face of die to value from 1-6 3. getFace() method provides current face to the main program 4. main create a Die object 5. main create a Die object 6. main rolls die 5 times 7. main computes sum of rolls 8. main computes actual average of the rolls <--------- Code...

  • Can anyone help me with this java program? We are still very early with lessons so...

    Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class             The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • please give an answer in c ++. Question 3: assign a secret value in your program...

    please give an answer in c ++. Question 3: assign a secret value in your program and ask the user to enter a guess. if the guess is greater than the secret value, print too large; if the guess is less than the secret value, print too less; if the guess is same as the secret value, print you found it. the user has unlimited attempts or terminated by entering a non-number. Question 4: use rand() to simulate a double-dice...

  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • need help with dice excercise For example, if we were writing a calendar program of some...

    need help with dice excercise For example, if we were writing a calendar program of some sort, we might very well use an array with 366 spots to hold the days, not worrying about adding more days to the year. Exercise 23 (C level] For another example, suppose we want to simulate rolling two six-sided dice repeatedly, tallying how many times each total is rolled. We need a memory cell to count the number of times each of the possible...

  • I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions...

    I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions only as (DieRoll, Guess, cnt1, cnt2) followed by this statement: srand((unsigned int)time (NULL)); which will give the random number generator a random starting point. Note: srand and rand require the TIME.H (or iomanip) cnt1 and cnt2 will be used in Chapter 5 drop box as counters for loops. Do NOT create additional variables. Points will be taken off for any additional variable creation. 2....

  • C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their...

    C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their manual payroll system to a computer-based system. Write a program to produce a 1-week payroll report for only one employee to serve as a prototype (model) for the administration to review. Input for the system will be the employee’s 4-digit ID number, the employee’s name, hours worked that week, and the employee’s hourly pay rate. Output should consist of the employee’s ID number, the...

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