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
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
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
Summary: Well. The first thing you must have understood is the way that C implements the arrays. Basically in C a pointer and an array is the same thing. A pointer is a 4bytes (or 2 sometimes) integer variable...
Summary: im at a bit of a loss here. I never had to work with strings, so forgive me if it is trivial: i want to have an array of strings in C++, for example: string array[10]; array[0] = "I dont"; array[1] =...
Summary: What you're talking about is using pointers and allocating memory. You need to be careful here because this is how memory leaks occur: #include "stdlib.h" /* your array: */ char *array; /* sizing you...