This is what i have so far. I'm not completely sure if this correctly assigns the random numbers to the array, so if it doesn't let me know. But I need a simple way to find the max value from the random generated numbers. Any help would be greatly appreciated.
You could loop through the array, and compare against the highest number you have found so far until you've looped through the entire array. That will get you the max.
#include <iostream>
#include <cstdlib> // for rand and srand functions
#include <ctime>
usingnamespace std;
int main()
{
int num = 0;
int ray [30] = {num};
srand(1);
for (int i = 0; i < 30; i++)
{
num = rand() % 100 + 1;
cout << num << " ";
}
Apologies, I assumed, for some reason, you had an array. But in any case you'll need a variable to keep track of the highest number you've seen so far.
As Zhuge says you need to include a method of identifying which num is greatest like:
L16 ........MAX=num; //assign the 1st num to MAX
L17 if(num>MAX)MAX=num; //upgrade MAX if next num>MAX
L18 cout<<"The maximum random number generated : "<<MAX;