I have to write a function to populate a 50 element integer array with random numbers: 100 <= # <= 1000. I have everything I need in the code except the "between 100 and 1000." The things I'm trying are not working. Thanks!

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std ;

const int ARRAY_SIZE = 50 ;
int popList[ARRAY_SIZE] ;
int populateArray(int popList[]) ;
int printArray(int popList[]) ;

int main()
{	
	srand( time( NULL) ) ;
	
	populateArray(popList) ;
	printArray(popList) ;

		
return 0 ;
}

int populateArray(int popList[])
{
	int i = 0 ;
	for (int i = 0; i < ARRAY_SIZE; i++)
	{
		popList[i] = rand( ) % 1000  ;
	}

	return i ;
}
	
int printArray(int popList[])
{
	int i = 0 ;
	for (int i = 0; i < ARRAY_SIZE; i++)
	{
		if ((i+1) % 10 == 0)
			cout << popList[i] << " " << endl ;
		else
			cout << popList[i] << " " ;
	}

	return i ;
}

I have everything I need in the code except the "between 100 and 1000."

//Line #28 should be this:
popList[i] = rand( ) % 901 + 100  ;

Edited 7 Years Ago by Clinton Portis: wonder if tiger woods was penalized for going out of bounds...

This question has already been answered. Start a new discussion instead.