Coding help
I'm just learning C++ so I was just trying to think of something that wasn't pointless to practice on. So I decided to use this. I still don't understand what I need to do :S
Quote:Original post by KingRage
I'm just learning C++ so I was just trying to think of something that wasn't pointless to practice on. So I decided to use this. I still don't understand what I need to do :S
What you need to do as far as assigning or initializing before comparing? Sorry if I went on a tangent above and wasn't clear, but here's the breakdown. You have this line of code:
while(strPw != strRe)
Look at every single line of code above that line. There are no lines that give strRe a value. How can you know that strPw is notequal to strRe if you don't know what strRe is? I don't know what it is supposed to be or I could help you further. (Because strRe is not a very definitive name). Ponder this:
string string1;string string2;string1 = "Hey";while(string1 != string2) { /* Do stuff */ }
So we know that string1 is "Hey". You tell me. Is string2 equal to string1?
If you said "I don't know because I don't know what string2 is!" then you've got it.
Quote:Original post by Lacutis
"Your way works in this instance by pure chance. It's very possible that your code could not work when compiled with a different compiler or for a different platform, or depending on whats in the memory allocated to your test variable at the time it's created."
Perhaps it would be illustrative if KingRage inserted...
cout << strRe << endl;
into his code somewhere before...
cin >> strRe;
...just to show him what he is comparing strPw to.
If you're just trying to make sure your loop executes once, use the "do while" loop shown above.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement