how would I create an array of four strings and initialize the first three items to a value and then change the value of the first item and then add the fourth item and if I try to add another item give an error message?
Thank you all for your help!
Thank you, here is what I have so far?
If nothing else if you could point out what I am not understanding about this, I am just learning this language and I think my school maybe using a book that is not that up to date?
Your code is just fine, you found out two things u made error:
if you declare
string inventory, if u want to get the first node of the array, you should call inventory, not inventory
u should know difference between
i++, and ++i
here is an example:
1 2 3 4
// A contains 4, B contains 4
1 2 3 4
// A contains 3, B contains 4
Declaring variables at the beginning of the function is something that is necessary in C, but not good C++ style. I would declare lastItem inside the scope of the loops. (It then becomes a different valiable in each loop):
string lastItem = inventory[i];
i++ is not in any way better than ++i. In this case there is no real difference, but the prefix operator (++i) will in other cases result in simpler code. It's a good habit to use ++i.
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: