-
random number help
I am trying to simulate the rolling of a six sided die ten time...but get a compile error.
Code:
#include <cstdlib>
using std::rand;
using std::srand;
#include <iostream>
using std::cout;
using std::endl;
#include <ctime>
using std::time;
int main()
{
const int arraysize = 7;
int value[arraysize] = {0};
srand( time( 0 ) ); // seed random number generator
for( int roll = 1, roll <=10, roll++) // roll die 10 times
value[ 1 + rand() % 6]++;
cout << value << endl;
system("PAUSE");
return 0;
}
Errors:
22 C:\Dev-Cpp\main.cpp expected init-declarator before '<=' token
22 C:\Dev-Cpp\main.cpp expected `,' or `;' before '<=' token
26 C:\Dev-Cpp\main.cpp expected `)' before ';' token
-
Take a look at the second error message and you'll get there.
-
-
array indexes are zero based
0,1,...6 are valid indexes, so why are you using 1..6?