Question
Hello. I am in need of assistance; currently working on a program that ask the user to input a certain amount of dice rolls to
Hello. I am in need of assistance; currently working on a program that ask the user to input a certain amount of dice rolls to be simulated (in my case 500) using 4-dice. The program then keeps track of how many times a certain number between 4 and 24, the minimum amount all four dice could sum up to and the maximum, and print a bar graph histogram using "X"s. I have managed to get the program to compile and run but when it comes to printing the correct number of rolls in the form of "X"s, it goes on. Here is one example of what the program could look like: How many rolls do you want? 500 (this is the user input) 4: 5:X 6:XXX 7:XXXXXXXXXXXXXX 8:XXXXXXXXXXXXXX 9:XXXXXXXXXXXXXXXXXXXXXXX 10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 11:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 12:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 13:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 14:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 15:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 16:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 17:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 18:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 19:XXXXXXXXXXXXXXXXXX 20:XXXXXXXXXX 21:XXX 22:XX 23: 24:X In this example, we asked the program to simulate 500 4-dice rolls. The sum was never four, the sum was five on 1 of the 500 trials, the sum was six on 3 of the trials, etc. Help would be greatly appreciated! Thank you in advance. Below is my current code. The idea behind it is, it calls function roll(), takes that result and stores it in variables roll(1-4), using a random roll function. Afterwards it adds each up and gets a sum. This rollsum would then go into an if-else-if, that checks to see which of the possible 4-24 totals it landed on. Once the correct number is found, a counter is incremented and stored in an array. Once the total rolls are simulated and all counters are incremented correctly in their correct array index, the array is passed on to function printHistogram(). Here is where the printing of a similar image found above is suppose to take place.
Apologies, I cannot submit my code on here as it is too long.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started