Re: [RESOLVED] What's wrong?
No, the problem is you're calling srand inside your loop. You should only call it once.
Re: [RESOLVED] What's wrong?
this is not correct ...
that is declaring the array with size 0 (I'm not sure if that is legal or not).
In your "for(;;)" loop, you need to initialize the array to 0 ...
Code:
int hits[max];
for (i=0; i<max; ++i)
hits[i] = 0;
As mentioned, you only need to call srand() once at the start of the program.
But your usage is OK.
Re: [RESOLVED] What's wrong?
Quote:
Originally Posted by
Philip Nicoletti
that is declaring the array with size 0 (I'm not sure if that is legal or not).
It's not legal to specify a static array (or dynamic array) of size 0. This is actually used as a way to implement compile-time assertions.
Note however, that the OP's original program uses neither; it uses a variable length array, which is a language extension. IMO, it's better to just use a std::vector instead. In that case the initialization is also very simple.
Code:
std::vector<int> hits(max, 0);