need help with programing assignment. thanks

Create a function “int roll()” that returns a value from 1 to 8.
Section 2
Main Function. Set the random number seed with 1 followed by last
4 digits of your student ID. my number is 16354.
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 5 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. */

this is what i have so far:
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<iomanip>
using namespace std;
int roll();



int num2;


// Section 1
int roll()
{
	num2 = ((rand() % 8) + 1);
	return num2;
}

int main()
{
	static int num1 = 16354;
	srand(num1);
	int arycount[9] = { 0 }, i, i1, i2, i3, i4, i5,i6, totalsum = 0, arycount2[9] = { 0 };


	for (i = 0; i < 200; i++)
	{
		arycount[roll()]++;
	}
    
	for (int i1 = 1; i1 <= 8; i1++)
	{
		cout << i1 << ' ' << ':' << ' ';

		for (int i2 = 0; i2 < arycount[i1]; i2++)
			cout << '*';
		cout << "." << endl;
	}
	for (i3 = 0; i3 < 1000000; i3++)
	{
		{
			for (int i4 = 0; i4 < 5; i4++)

				totalsum += roll();
		}
		arycount2[totalsum]++;
        	}
	for (i5 = 5; i5 < 41; i5++)
	{
		cout << setw(1) << i5 << ' ' << ':' << ' ';
		for (int i6 = 0; i6 < arycount2[i5]; i6++)
			cout << '*';
		cout << "." << endl;
		
	}

} // main  
Last edited on
I have the same but I could not get anything
if u get anything & can help text me please 8322828144
thanks
do you have any question?
Havent been able to get the correct output. Im stuck at section 5 6 and 7. When i try and run my program it says the program has stopped running and crashes
Have you examined the numbers being returned by your roll function? Are you certain that, when you use the result as an array index:

arycount[roll()]++;

that you are not attempting to write beyond the end of the array?
i need the program to get an output like this:
output example:
1: 30: ******************************
2: 40: ****************************************
3: 45: *********************************************
4: 36: ************************************
5: 49: *************************************************

8: 1: *
9: 15: *
10: 106: *
11: 294: *
12: 828: *
13: 2015: **
14: 4112: ***
15: 8142: *****
16: 13944: *******
17: 22440: ************
18: 33426: *****************
19: 46892: ************************
20: 61240: *******************************
21: 75027: **************************************
22: 87266: ********************************************
23: 95331: ************************************************
24: 97483: *************************************************
25: 95145: ************************************************
26: 86909: ********************************************
27: 75659: **************************************
28: 61257: ********************************
29: 46917: *************************
30: 33497: ******************
31: 22583: *************
32: 14090: *******
33: 8041: *****
34: 4102: ***
35: 2007: **
36: 817: *
37: 311: *
38: 83: *
39: 17: *
40: 3: *
i can only get the top part out of what i got so far. need help getting the bottom section.
If you're going to ignore the things people post, then what's the point in us posting?
# include <iostream>
#include <stdlib.h>
using namespace std;

//////////////Section 1///////////////
int roll();

void main()
{
////////////Section 2/////////////
cout << "Please enter the last four digits of your Student ID" << endl;
int ID = 0;
cin >> ID;

srand(10000 * ID);

int Array[7];
for (int i = 0; i < 7; i++)
{
Array[i] = 0; //Cleaning array
}

//////////////Section 3////////////////
for (int i = 0; i < 200; i++)
{
int Random = roll();
Array[Random - 1]++;
}

//////////////Section 4////////////////
for (int i = 0; i < 7; i++)
{
cout << i + 1 << " : " << Array[i] << " : ";
for (int j = 0; j < Array[i]; j++)
{
cout << "*";
}
cout << endl;
}

//////////////Section 5////////////////
int Random = 0;
for (int i = 0; i < 6; i++)
{
Random = Random + roll();
}

//////////////Section 6////////////////
int BigArray[42];
for (int i = 0; i < 42; i++)
{
BigArray[i] = 0; //Cleaning array
}
int BigRandom = 0;
for (int i = 0; i < 1000000; i++)
{
for (int j = 0; j < 6; i++)
{
BigRandom = BigRandom + roll();
}
BigArray[BigRandom - 1]++;
}

//////////////Section 7////////////////
for (int i = 5; i < 41; i++)
{
cout << i + 1 << " : " << BigArray[i] << " : ";
for (int j = 0; j < BigArray[i] / 2000; j++)
{
cout << "*";
}
cout << endl;
}
}

int roll()
{
int Random = rand() % 7 + 1;
return Random;
}


then wait 10 -15m to get the output for screenshot
Topic archived. No new replies allowed.