For a class I am taking I need to produce 1000 random numbers and store them in an array. I am totally lost and need some help. If someone can get me started on the program it would help me. Also, i need to write a function to find the array's max, min, and average values.

10 Years
Discussion Span
Last Post by Etniespr101

Did you search for previous answers to this common problem?

> I am totally lost and need some help.
I'm going to assume that you've successfully completed some previous assignment, and that the idea of being "totally" lost is an exaggeration.

For example, could you write a program which printed 1000 random numbers. It would be a big start, and show us that you're not looking for a free lunch.

See the readme's at the top of the forum.


I'm also pretty sure that your professor must have given you a specific range of which to get the 1000 numbers. By that I mean...is it a range of numbers between 1 & 5 billion??? Some steps for you and as brought out by Salem...we'll not do your assignment, but we'll guide you and when you get burned out and stuck, we'll try out best to bail you out. A few things:
1. First you'll need to create to use a C++ random generator function. i.e.

srand((unsigned int)time(NULL));

2. You'll need to create an array to store the 1000 numbers. i.e.


3. The average:


4. For the maximum and minimum:

min = 32767
max = -32767
for (i=0; i<count; i++)
max = number[count];
if (number[count]<min)
min = number [count];
}//end for i
cout<<"Max = "<<max<< "and Min = "<<min<<endl;

5. Before posting in the future, chances are that your assignment has been addressed. Please search the forums for similar programs and see if you understand it. Also read the FAQ and Forum Rules to get aquainted with the forum. Welcome aboard and hope you enjoy it. Please do read up on arrays.


i have figured out the majority of the program but i just got stuck. so far i have

#include <iostream>
#include <cmath>
using namespace std;

int line(int, int);
int average(int, int);

int main()
	int array[1000], arrMax, arrMin, size=1000, seed, i;

	line(array[i], size);
	average(array[i], size); 

	cout << array[i];

	return 0;

int line(int array[], int size){
	int i;

	for (i=0; i < size; i++){
		cout << array[i];

	return 0;


int average(int array[], int size){
	int sum, i, number;
	double average;

	for (i=0; i< size; i++){
		number = array[i];
		sum=array[i] + number;
	return average = sum/size;


I do not know what libraries to include and what to do next. If I can get some advice it would be great!


Also, where is your random number generator to get the numbers, or will the user input the numbers??? I doubt that the numbers will fall out of the sky and go into you're computer....try a little harder please. Again i ask....I'm also pretty sure that your professor must have given you a specific range of which to get the 1000 numbers. By that I mean...is it a range of numbers between 1 & 5 billion??? What should be the highest and the lowest number?


> int line(int, int);
If you make this match your function definition, that would be an improvement.

> line(array, size);
To pass an array to a function, it's just the array name, like so
line(array, size);

> cout << array;
Use the same kind of for loop you use in your functions.


Also, you should use "srand" so that your output isn't the same every time you run the program. as zandiago shows above...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.