Void Function Arrays

Hi Guys,

Need some help and keep getting stuck.

Need to populate an array [100] using srand() and rand() with random #s 300-500 with a while loop using a void function.

I could not get the While loop to work. Trying to use a for seems easier so I tried that as well.

I also need to search the function to determine how many of those array elements are between 320 and 445



#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void fillArray(int randNums[], int 100);

int main()
{
//declare array
int randNums[100];

return fillArray;

for (int sub = 0; sub < 100; sub += 1)
{
cout << "array " << sub + 1 << " " << randNums[sub] << endl;
} //end for


system("pause");
return 0;
} //end of main function

void fillArray(int randNums[], int 100)
{

srand(static_cast<int>(time(0)));


for (int sub = 0; sub < 100; sub += 1)
{
randNums[sub] = 300 + rand() % (500-300 + 1);

}
}
This line right here:
 
return fillArray;


ends your main. Nothing beyond this will be called. I believe you want this:

 
fillArray(randNums, 100);


you also want to re-declare your fillArray function:

 
void fillArray(int randNums[], int n);  //n is the number of entities 
Topic archived. No new replies allowed.