The program is not working because rand() function does not take and
argument. You have to grab 100 random numbers in an array and then have to
find maximum / minimum of them after sorting the array.

 

  _____  

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of
fecress
Sent: Wednesday, March 12, 2008 11:38 PM
To: [email protected]
Subject: [c-prog] Please help to determine minimum,maximum and average on
Rand() values

 

Hello all,

int main()
{
int how_many = 100;

cout << "Print " << how_many << " random integers.\n";

for (int i = 0; i < how_many; ++i)
cout << rand() << '\t';

I need to add code to the above programm that determines the average, 
maximum and minimum values generated by the above programm.
The programm below is what I have so far and seems that i can't get 
through. Please I need your help.
This is what I have:

/*The program determines average, maximum, and minimum values 
generated by 100 random numbers.*/ 

/*Begin of pre-processing directive block*/
#include <iostream>
#include <stdio.h> 
#include <stdlib.h> 
using namespace std;
/*End of pre-processing directive block*/

/*Begin of main function*/
int main()
{
int how_many = 100;
int max, min, ave;

cout << "Print " << how_many << " random integers.\n";

for (int i = 0; i < how_many; ++i)
cout << rand() << '\t';
for (int i = 0; i < how_many; ++i)
if (rand(i) < rand(i+1))
max = rand(i+1);
else 
min = rand(i);

ave = (max - min) / 100;
cout << "The maximum value generated = " << max << endl;
cout << "The manimum value generated = " << min << endl;
cout << "The average value generated = " << ave << endl; 

system("PAUSE");
return 0;
} // End of main function 

Please help!!!

 



[Non-text portions of this message have been removed]

Reply via email to