For whatever reason, the for loop can find the maximum value of the randomly generated array O.K., but when it tries to find the minimum or sum the array it is wrong.
Any help is appreciated! I've been working on this for days though it should be easy enough...
Thanks in advanced.
The minimum is wrong? In what way? What did you expect, and what did you get instead? (I can see how the sum is wrong, but it isn't obvious to me why the minimum is wrong.)
It gives me a value of 0 for the minimum value every time.
Sorry, I put the sum back to "sum = sum + number[a]". I had changed this when trying to get it to work, however even this still doesn't calculate the sum.
I'm looking, I don't see the issue... it would make sense I was getting a very large sum if I was accidentally assigning too many values to the array, but from what I see, I'm not..
Well, you have the same issue with sum, as with the other loops -- but that will cause the sum to be slightly too small, not too big (and I assume that you fixed that loop already).
BTW, just how big a value are we talking about here?
Henry Wong wrote:BTW, just how big a value are we talking about here?
From 1 to 100 (inclusive), so with only 15 values there should not be any overflow.
Joe, what is the sum you are getting? It should be anywhere between 15 (all ones) and 1500 (all hundreds). Well, after you've fixed your loop condition, otherwise it's between 14 and 1400.
Joe Saunders wrote:I understand why it should be < 1500 and > 15 but I get numbers with 5 digits such as 75615, depending on which values are assigned.
Please post your latest code -- as it isn't possible to get what you are describing with your previous code.
Never mind.... I think I figured it out. Hint: is "75615" really the sum? Or is the sum "756"?
I thought that might be the issue Henry, however it doesn't seem to be that way.
To show... I ran the program and get these numbers:
83, 19, 30, 55, 7, 28, 49, 10, 15, 9, 32, 39, 74
The sum should be 450, however I receive a sum of 53144 from the program.
How many numbers are in that list? (Hint: you have too many magic numbers in your code.)
And why are you printing your results in such a strange way? (Hint: change it to print an exclamation mark after the sum and you'll see why I call it strange.)