Dice Rolling
Consider the following program for dice rolling.
int main()
{
int p[6] = { 0 };
int i;
// srand((unsigned) time(NULL));
cout << "Please input an integer as the random seed -- ";
cin >> i;
cout << endl;
srand(i);
for (int k = 0; k < 20; k++ )
{
i = rand() % 6; // The value of rand() % 6 is 0 ~ 5
++p[i];
}
// Statistics of pips
for (i=0; i<6; i++)
cout << i + 1 << ": " << p[i] << endl;
return 0;
}
It will randomly generate 20 integers between 1 and 6; count the
occurrence of each number; and then print out the statistics.
Please modify the program so that the output will show a bar chart as
follows. (Please notice that the following is only an example.
The length of each bar may be different depending on the random number
generated.)
Please input an integer as the random seed -- 318
1: 3 ***
2: 5 *****
3: 5 *****
4: 3 ***
5: 1 *
6: 3 ***