Program for Random numbers having a bit of trouble.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 37
Reputation: radskate360 is an unknown quantity at this point 
Solved Threads: 0
radskate360 radskate360 is offline Offline
Light Poster

Program for Random numbers having a bit of trouble.

 
0
  #1
Jun 13th, 2007
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;


}
average = total2 / second;
deviation = sqrt((overall/second) - ((total2 * total2)/(second * second)));

cout << setprecision ( 2 ) << average << endl;
cout << setprecision ( 3 ) << deviation << endl;



Thank you all for any help you can give.

Radskate360
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Program for Random numbers having a bit of trouble.

 
0
  #2
Jun 13th, 2007
try writing down the s.d on paper for a few numbers.

Then walk through your program and place a few couts to see where it may be going wrong.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Program for Random numbers having a bit of trouble.

 
0
  #3
Jun 13th, 2007
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.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: anujsharma is an unknown quantity at this point 
Solved Threads: 0
anujsharma anujsharma is offline Offline
Newbie Poster

Re: Program for Random numbers having a bit of trouble.

 
0
  #4
May 20th, 2009
hi can anyone tell me how to generate random number within certain limit as in between 10 to 20 etc .please help me
Thanks
anuj
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Program for Random numbers having a bit of trouble.

 
0
  #5
May 20th, 2009
10..20 or 11..19 or what else?
[0,n) - 0, 1, ... n-1 :
  1. rand() % n
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC