Roll 2 dice 36000 times and tally the results using an array.
I'm very confused.
My program:
Code:
#include <iostream>
using std::cout;
using std::cin;
#include <cstdlib>
#include <ctime>
int roll_die( int );
void display( int [] );
int main()
{
int roll1;
int roll2;
int total;
int num[ 11 ];
srand( time( 0 ) );
for ( int a = 0; a < 36000; a++ ) {
roll1 = roll_die( roll1 );
roll2 = roll_die( roll2 );
total = roll1 + roll2;
num[ total - 1 ] = 1;
}
display( num );
cin.get();
return 0;
}
int roll_die( int roll )
{
roll = 1 + rand() % 6;
return roll;
}
void display( int number [] )
{
for ( int b = 0; b < 12; b++ )
cout << b + 1 << " was rolled " << number[ b ] << " times.\n";
}
My output:
Code:
1 was rolled 2009252814 times.
2 was rolled 1 times.
3 was rolled 1 times.
4 was rolled 1 times.
5 was rolled 1 times.
6 was rolled 1 times.
7 was rolled 1 times.
8 was rolled 1 times.
9 was rolled 1 times.
10 was rolled 1 times.
11 was rolled 1 times.
12 was rolled 1 times.
I understand that I might be doing this completely wrong; I haven't programmed in months, and I wasn't very good at it in the first place!