Write a custom function called diceRoll()to simulate a dice roll. The function s
ID: 3698323 • Letter: W
Question
Write a custom function called diceRoll()to simulate a dice roll. The function should return an integer value from 1-6 and does not accept any parameters (inputs). The function rand() from the <stdlib.h> header file can be used for this purpose. Before using the function, the random number generator must be provided a “seed” value. If the same seed value is supplied each time the program is run, the results of the random number generator will come out in the same order each time. A commonly used seed value is derived from the system clock, because the seconds count changes frequently enough to provide a different seed value each time we run the program. Include this in the beginning of your main program to seed the RNG:
srand(time(NULL));
To use the time function, <time.h> must be included. The rand() function returns a random integer between 0 and 32767. You will need to adjust the result to be between 1 and 6 for a dice roll. Use a for loop (in main) to call your function 100 times and then use switch-case statements to count how many times each number 1-6 was rolled. Print the total for each number. Finally, print the total number of rolls by adding up each count to verify that you have 100 rolls. You should seed the random number generator only once with srand(time(NULL)), but you can use the rand() function repeatedly during program execution.
*Please use C or C++ using (printf, scanf) or (cin, cout)*
Thank you!
Explanation / Answer
Hi below i have written a sample code for your reference,to simulate a dice roll. #include #include #include //The following function outputs a basic greeting to the user void greeting(int pnum) { if(pnum == 1) { std::coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.