Create Random Numbers to Populate Array

I'm doing someone else's homework. I saw someone else post this exercise and thought, "I can do that." Well, apparently... I can't

The problem is to create an array and populate it with random numbers. Then, sort the array. I'm doing something wrong trying to generate the random data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//randSort.cpp
//Generate 100 random numbers to populate an array
//Sort the numbers
#include <iostream>
#include <stdlib.h>
#include <time.h>
using std::cout;
using std::endl;

int sort(int array[]);

int main(void)
{
    int large[1000];

    for(int i = 0; i < 1000; i++)
    {
        //srand(time(NULL));
        large[i] = rand % 250;
    }

    for(int i = 0; i < 1000; i++)
    {
        cout << large[i];
        if(large[i] % 10 == 0)
            cout << endl;
    }

    return 0;
}


The errors I receive are associated with line 19:
1
2
3
Error	1	error C2296: '%' : illegal, left operand has type 'int (__cdecl *)(void)'	c:\users\killingthemonkey\...randsort.cpp	19	1	randSort

	2	IntelliSense: expression must have integral or unscoped enum type	c:\Users\killingthemonkey\...randSort.cpp	19	20	randSort


I've looked at the manual for random and I've looked at other people's code. I can't understand where my train is going off the rails.
Last edited on
Are you trying to generate random numbers up to 250? If so, then the syntax would be rand() % 250;
Here's the link for rand() http://www.cplusplus.com/reference/cstdlib/rand/
Made the change. Same error.
rand is a function.

Changed the line to:
large[i] = rand() % 250; //Like you pointed out

I am now generating random numbers.
Last edited on
Topic archived. No new replies allowed.