Hi! I've been interested in programming for a while now, so a couple of months ago a bought a book so I could teach myself. The thing is, I'm having some trouble with an excercise. It's objective is to build a program that, using arrays, shows the results of throwing two dice 36.000 times. I have written up this code:
Code:
// Ej. 6.19
// two dice throws
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 13
// main starts program
int main()
{
int total; // total of two dice throws
int throws; // counter for number of throws
int frec[N]; // frequency of dice throws
int start; // user starts program with this
srand( time (NULL) ); // random number generator
printf( "\nProgram to simulate the throwing of 2 dice 36000 times\n" );
do
{
printf( "To start, type 1.\n" );
printf( "Otherwise, type any other number to exit.\n" );
scanf( "%d", &start );
if( start != 1 )
break;
// throws dice 36000 times
for( throws = 1; throws <= 36000; throws++ )
{
total = ( 1 + ( rand() % 6 ) ) + ( 1 + ( rand() % 6 ) );
frec[ total ]++;
} // end of for
printf( "%s%17s\n", "Total", "Frequency" );
for( total = 1; total < N; total++ )
{
printf( "%5d%17d\n", total, frec[total] );
} // end of for
} // end of do
while( start == 1 );
return 0; // successfull end of program
} // end of main
But, the actual program running is really strane. The compiler (Dev-C++) didn't give any errors or warnings or anything.
Code:
Program to simulate the throwing of 2 dice 36000 times
To start, type 1.
Otherwise, type any other number to exit.
1
Total Frequency
1 2009284272
2 2294727
3 2009286276
4 2009148402
5 2297449
6 2009251663
7 2299872
8 2009289304
9 2009149352
10 2980
11 2009248549
12 2009306949
To start, type 1.
Otherwise, type any other number to exit.
Huge numbers.... No matter how many times I run it, even with srand, the numbers are about the same...
Could anyone tell me what's wrong with my code, please?