I am trying to write a program that takes a specif range from the user and generates 30 random numbers in that range. I have that part worked out and the code works fine but I have no clue how to take the average of those 30 random numbers. Could anyone offer some advice that would be great

Thanks

Init a variable to ie Sum = 0;

Run a for loop thirty times to get a total sum.

for( int i = 0; i < 30; i++)
{
Sum = Sum + array;
}

Then divide by 30

return Sum/30

That's the average!!

Add them to a sum using a loop, then divide by 30. That's generally how one would find the average of a list of numbers:

double sum = 0;

for ( int i = 0; i < 30; i++ )
  sum += a[i];

cout<<"Average: "<< sum / 30 <<'\n';

Thanks for you help I don't know why I didn't think of that I think it's just the array thing threw me off or something.

Anyways Thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.