Think about what the line in mantd's quote does.
"==" tests for equality. It is very important to not mix it with "="
which assigns a value to a variable
Think about what the line in mantd's quote does.
"==" tests for equality. It is very important to not mix it with "="
which assigns a value to a variable
Double Helix STL
Adding to what swgh said: In this loop you make 1 the exit value. Thus when the user enters 1, you want to get out of the loop and move on to the end of the code. Currently, you are only performing the loop while the number is equal to your exit value. != will perform the loop when the number is not equal to your exit value.
IMO your tutorial is not the best place to learn C++ since it appears to be teaching C style strings instead of C++ strings.
>> it shuts the program if u dont press 1 cuz of the cin.get()
Actually, the cin.get() attempts to keep the program open, but because you type 1 and then <enter>, the cin.get() is getting the <enter> instead of waiting for you to type more. A common way to handle this is to use cin.ignore() and then cin.get().
I don't see anything wrong with while (num == 1). It keeps asking you if you are ready until you say yes. That is correct to me.
Think about it. The end condition is 1, so testing for == 1 will loop while the exit condition is true.
No, the exit condition is anything but 1. An input of 1 means not ready. The loop runs while the user is not ready. That is why the inside of the loop repeats the prompt "Enter 1 if your not rdy".
I guess. I was thinking that if the user is not ready (1), it would quit, if not, it would continue with it's loop.
That would make sense, too, but based on the words in the prompt (and the fact that the OP said it was working) I'm guessing the other explanation is what was wanted.
Check my example mantd, daved is correct, that is what I did in my example. I think the OP has sused this at last. He has not been on here asking for anymore adivise
Double Helix STL
Yes, but I would instruct the OP to reverse this, as many programmers (like me and swgh) expect the while loop to continue while not *exit condition* or while *continue condition*. Nonetheless, in the code posted, I believe you are right.
EDIT: swgh, I said he was right.
>EDIT: swgh, I said he was right.
Lol sorry I missed that bit!
Double Helix STL
I was browsing around and just wanted to add that when you create any variable (integer, char, string etc) it is generally good practice to assign it a memory sector beforehand rather then later to insure the user will have enough free memory from the beginning to run the program.
Different types of variables are assigned memory sectors in different ways.
e.g:
Code:int someVariable = 0; or string someOtherVariable[21] = {0}; or char someCharacter = ' ';
Repost....
When you declare a variable, it is allocated space on the stack. Assigning a value to that memory doesn't "assign it a memory sector".
But still, initializing variables is a good idea anyway. (Although most compilers will warn you with warnings turned on when you use a variable that might not have been initialized.
[edit] There's no need to double-post. It often takes a few seconds after you click the button for the post to appear. [/edit]
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Simply declaring an int is enough to give it space to run. The reason to initialize it to a value (usually zero) is to make sure that the variable has a known value before it is used.