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
|