well for one you can use NULL in replace of 0, if you get that unsigned error, or.
srand((unsigned)time(NULL)); but your example, and the 2 i just listed work fine, it's only some compilers complain. I'm sure there's a valid explanation for this but I am unsure of it.
additionally I would use a constant for 100, and also for 50 as that way if you or someone else later on down the track want to change the amounts then they don't have to hard code it into everything, just a simple change of const value and bob's your uncle.
I'll write some sample code to demonstrate:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <ctime>
using namespace std;
const int arraySize=50;
const int range=100;
int main()
{
int array[arraySize];
for (int i=0;i<arraySize-1;i++)
{
array[i]=getRand();
}
return 0;
}
int getRand()
{
return 1+rand()%range;
}
|
EDIT: I actually didn't notice you have for loops in your last code because it was tabbed so poorly. you need to watch your indentation, also in your for loop you are saying while i less than 50, which means i starting at 0 has 50 elements so up to 49, but your asking for it to count to 50, which is actually counting 51 elements in the array. when you declare an array just remember the last element is always -1. for example if i declare an array of 99 elements then the last element is 98. because 0 is 1st, 1 is 2nd, 2 is 3rd, etc. well, 0 is actually the zeroth, 1 is the 1th(oneth), 2 is the 2th(twoth) and so on :P which is confusing way to look at it, it is much easier to just remember to minus one for whatever the declaration is.
goodluck