array histogram rand()

Section 1 create a function “int roll()” that returns a value from 1 to 5.
Section 2 Main Function. Set the random number seed with 1 followed by last 4 digits of your student ID.
Section 3 Call "roll" function 200 times while keeping count of each number. (You are required to use an array)
Section 4 Show the results, and display a histogram.
Section 5 Call "roll" function 8 times, and add those numbers
Section 6 Repeat "Section 5" 1,000,000 times while keeping count of each number. (You are required to use an array)
Section 7 Show the results, and display a histogram. This time each "*" represents 2000./*

I think I have done section 4 through 7 correctly but, i cant get section 1 through 3 to display 200 rolls only using 5 numbers. the only way i seem to get 200 rolls is if i use 7 numbers. check the links at the bottom to see the differences in output. the only changes made between the two is on line 28 i believe "i<8" vs "i<6"

heres the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<iomanip>
using namespace std;
int roll()
{
return (rand() % 7) + 1;
}
void main()
{
int ary[9] = { 0 };
int arx[43] = { 0 };
int id = 19121;
srand(id);
int i, j;
for (int i = 0; i<200; i++)
{
ary[roll()]++;
}
for (i = 1; i < 6; i++) 
{
cout << setw(1) << i << ":" << setw(6) << ary[i] << ':';
for (j = 0; j<ary[i]; j++)
{
cout << "*";
}
cout << endl;
}
for (i = 0; i<1000000; i++)
{
arx[roll() + roll() + roll() + roll() + roll() + roll()]++;
}
for (int i = 8; i<41; i++)
{
int j;
cout << setw(2) << i << ":" << setw(8) << arx[i] << ":";
for (j = 0; j<arx[i]; j += 2000)
{
cout << "*";
}
cout << endl;
	}
}


here is a link to the output with i<8: https://onedrive.live.com/redir?resid=3274BC86E4F10732!1681&authkey=!AKpIVw8FicEV8E0&v=3&ithint=photo%2cpng
here is a link to the output with i<6: https://onedrive.live.com/redir?resid=3274BC86E4F10732!1682&authkey=!AILbv30Yg1KScxo&v=3&ithint=photo%2cpng
Last edited on
Please don't create multiple threads about the same problem.
Topic archived. No new replies allowed.