Tony:(posted 6950 days ago)
I can step through the program using z [enter] but the variable values which you mention in the book just don't appear on my screen.
What does appear on your screen? Anything?
You say that I should expect a message similar to :
"You have tried to use element 51082 of a vector which has only five elements. "
Well, I tried that several times and the output is always the same. I don't get any message, just:
The Highest weight was: 0 The Second Highest weight was: 0 The Third Highest weight was: 0
Am I going crazy or just missing something obvious that's staring me in the face?
No, you're not going crazy. The problem is simply that when you're dealing with uninitialized variables, you don't know what is going to happen. In your case, it happened that the values in those uninitialized variables were 0. Therefore, the program worked all right. However, if someone else did the same thing, they might get different results. That's why you have to make sure to initialize your variables before use.
[ Previous | Next ]