| | |
Program for Random numbers having a bit of trouble.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 37
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- C++ Random Numbers (C++)
- Program will not generate random numbers (C++)
- generating random numbers into an array.. (Java)
- Trying to find a better way to generate random numbers in Dev Pascal (Pascal and Delphi)
- Random numbers...really random?? (Java)
Other Threads in the C++ Forum
- Previous Thread: visual c++ 6
- Next Thread: Guessing Game
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






