Computing.Net > Forums > Programming > c++ array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

c++ array

Reply to Message Icon

Name: winpuslikr
Date: October 22, 2007 at 17:19:01 Pacific
OS: vista
CPU/Ram: dual core.2gb
Product: HP
Comment:

I'm very new to c++ I'm trying to write a program with an array using a random number generator from 1 to 1000. alist have to find te largest, smallest numbers and the average of the numbers. PLEASE HELP



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 22, 2007 at 17:28:31 Pacific
Reply:

We're willing to help you with your homework, but we won't do it for you. Tell us what you have, or at the very least, what steps you think your program needs to take to reach your goal.


0

Response Number 2
Name: winpuslikr
Date: October 22, 2007 at 17:54:01 Pacific
Reply:

I know to use a number rand generator. The problem I'm having is how to use te if and if else to fiqure out the largest,smallest numbers and the average.


0

Response Number 3
Name: Razor2.3
Date: October 22, 2007 at 18:54:05 Pacific
Reply:

That's easy enough to do:
int val, min, max, avg;
max = avg = 0;
min = -1 ^ (1 << sizeof(int) * 8 - 1);
for (int i = 0; i < 1000; i++) {
//load your random number into val here
if (val < min) {
min = val;
}
if (val > max) {
max = val;
}
avg += val;
}

Note: On the first min = line, we're shoving in the largest value possible into min. That way, the first random number is guaranteed to be smaller than min.


0

Response Number 4
Name: winpuslikr
Date: October 22, 2007 at 20:00:00 Pacific
Reply:

thanks for the help.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++ array

C++ Array Pointer Parameter www.computing.net/answers/programming/c-array-pointer-parameter/6482.html

C++ Arrays (Simple Q) www.computing.net/answers/programming/c-arrays-simple-q/4274.html

C++(arrays) www.computing.net/answers/programming/carrays/931.html