Program for Random numbers having a bit of trouble.
Expand Post »
HI,
I have been working on this program for a bit now and having a little bit of trouble, I have got most of it but still a few stumbles.
Here is the Directions:
Write a program that will generate an unknown (between 93 and 139) count of random numbers whose values fall between 147 and 206. Calculate the average to 2 decimal places and standard deviation to 3 decimals. On the monitor display only the count of numbers, the mean, and the standard deviation. Then after you have displayed alll of that information list them again in 5 columns in order from high to low and then have skipped two spaces.
I just chose lower numbers than required for now to see if I can figure this out any easier.
So far I can get everything to work but coming out with strange numbers for standard deviation and average.
std deviation is sqrt of ( 2 2
sum of num (sum of num)
_____________ ___ _____________
2
count count
this is what i have so far:
srand((unsigned int) time (NULL));
int first, second;
int high, low, high2, low2;
int number, number2;
int total, total2, overall;
double average, deviation;
high = 3;
low = 2;
high2 = 10;
low2 = 5;
for (first=0; first<1; first++)
{
number = rand()%(high-low+1)+low;
}
for (second=0; second < number; second++)
{
number2 = rand()%(high2-low2+1)+low2;
total = number2 * number2;
total2 = total2 + number2;
overall = overall + total;
cout << number2 << endl;
Re: Program for Random numbers having a bit of trouble.
Strange values usually means you didn't initialize a variable somewhere. For example, you don't initialize total2 when it should be set to 0 for an accurate sum.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Previous Thread in C++ Forum Timeline:visual c++ 6