The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Ask the user for a number, call it n
? Run n experiments, where each experiment rolls 4 dice and adds them up
? Keeps track of the total of the 4 dice in each experiment
? Prints out the histogram showing how many times each total occurred (so in total it should print out n of the X symbols)
This is what I have so far but I don't know what to do next.
#include <iostream>
#include <cstdlib>
#include <ctime>
void printHistogram(int counts[])
{
for (int i = 4; i <= 24; i++)
{
std::cout << i << ":";
 Â
for (int j = 0; j < counts[i]; j++)
{
std::cout << "X";
}
 Â
std::cout << std::endl;
}
}
int rollDice (int n)
{
int rollDice1;
int rollDice2;
int rollDice3;
int rollDice4;
int sumDice;
srand(time(0));
for (int runN = 0; runN <= n; runN++)
{
for (int startDice = 0; startDice < n; startDice++)
{
rollDice1 = rand() % 6 + 1;
rollDice2 = rand() % 6 + 1;
rollDice3 = rand() % 6 + 1;
rollDice4 = rand() % 6 + 1;
sumDice = rollDice1 + rollDice2 + rollDice3 + rollDice4;
}
}
}
int main()
{
int n;
std::cout << "Enter a Number n:";
std::cin >> n;
int testCounts[24]; // more than enough space
for (int i = 4; i <= 24; i++)
rollDice(n);
testCounts[i] = rollDice(n); // fill array
printHistogram(testCounts); // Call your method
}
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll