Hello, I have been assigned a program where you need to ask the user how many random numbers they want to display, generate that many random numbers, loop them into an array and then display the numbers that are in the array. I have all of that finished.
Now for the problem.. The end of the assignment is to display the lowest and highest number in the array along with the average and total of the numbers in the array. How can I do this. Sorry if this seems like an easy question. I generally get stumped on the easiest parts of assignments.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main ()
{
int randNum;
int x = 0;
int y = 0;
srand (time(0)); //Initializes random number generator
cout << "How many random numbers would you like to generate?" << endl;
cin >> randNum; //Gets users input on how many random numbers to generate
int array[randNum]; //Declares size of the array.
for(x = 0; x < randNum; x++) { //Loops through the array passing on the random numbers into the array
array[x] = rand() % 500 + 1;
}
for(y = 0; y < randNum; y++) { //Loops through the array displaying all of the random numbers generated
cout << array[y] << " ";
}
return 0;
}
//How can I Display the lowest and highest number in the array along with the average and total of the numbers in the array?