Hello, I'm an aspiring c++ coder, I'm using two books:"Learning to Program in C++" By Steve Heller, ISBN: 0-13-032410-8 ; And "C++: The Complete Reference Third Edition" By Herbert Schildt.
I usually lurk and just absorb the discussions around here, however I've gotten to a point in my studies where I have a question and this board seems to be a great place to ask it.
Ok so I'm up to vectors in the first book pp,159.
And I'm a bit confused. Here is the code snippet and my questions.
************************************************** *****************************************
vector<short> Weight(5);
vector<short> SortedWeight(3);
short HighestWeight;
short HighestIndex;
short i;
short k;
So far I understand perfectly.
cout << "I'm going to ask you to type in five weights, in pounds." << endl;
for (i = 0; i < 5; i ++)
{
cout << "Please type in weight #" << i+1 << ": ";
1.)
Ok I understand what he's doing by using i+1 to make the weight number on the prompt increment each time
through, however doesn't this expression change the value of i and there fore screw up the for loop
conditional statement?
cin >> Weight[i];
2.)
Ok, this part confuses me, Are we putting the value into the variable i? and if so won't it screw up the conditional statement of the for loop? Whats going on here? How can the i in the for loop, the i in the
cout expression and the [i] in the Weight index variable not become corrupted with constant value
changes, as there are different processes at work independantly in the for loop condition, the cout
expression, and the vector Weight?
Does The [i] in Weight simply mean "Process or deal with this index as a list?" So if I entered 5 values
into Weight would they be stored in each of the five elements which where declared on each respective
turn through the for loop? And if so why not just say "cin >> Weight;"? Why the [i]? and why i?
why not [weight] or [w]?
}
************************************************** *****************************************
Thanks a lot for your time, I really appreciate this.
Dreamerv3@mail.com



LinkBack URL
About LinkBacks





(off topic, I HATE coding in VBA).
