Sorry I messed up the post anyways avansc is right and also
you are missing two important things:
#include <string>
and
cout << "Well, hello, " << name << ", how are you?" << endl << endl;
I recommend using cin.ignore() after each cin to kill the
newline in the buffer or change all variables to strings and
use getline(cin, string variable); the third parameter is an
optional terminating character.
Ah, thanks, thought that might be a bit of a problem.
zodiac976 wrote:#include <string>
and
cout << "Well, hello, " << name << ", how are you?" << endl << endl;
I recommend using cin.ignore() after each cin to kill the
newline in the buffer or change all variables to strings and
use getline(cin, string variable); the third parameter is an
optional terminating character.
That would also help, heh. I don't really get what you mean by the newline in the buffer.
When you use cin, "\n" is left for processing, so you have to do something to eat it, otherwise if you call getline(), it'll return immediately, since it goes until it finds a \n. You can get rid of this "\n" so that your getline() doesn't immediately return in a whole slew of ways:
cin.sync()
cin.ignore()
getline(cin, myDummyString); [where myDummyString is a C++ string, as opposed to a character array]
cin.getline(myCharacterArray, sizeof(myCharacterArray)-1)
If you use cin.getline() or getline(), "\n" is not left on the buffer. Rather, it is automatically discarded.
cin.sync() looks like the "best" option, but I haven't used it yet.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
if(mood == "good" || "Good") doesn't mean 'if your mood is good or Good". The || is used like if(condition ||condition). So you have to check "good" and "Good".
i think the best paint program would be microsoft paint + paint.NET+graphics gale + Paint shop Pro 7 + photoshop CS3, it would be called Paint Gale Pro Shop.NET,
derbon wrote:if(mood == "good" || "Good") doesn't mean 'if your mood is good or Good". The || is used like if(condition ||condition). So you have to check "good" and "Good".
as far as i'm aware the latter part of the satement is wrong, mainly because you are evaluating whether the string "Good" is true or false, when you are supposed to be evaluating whether mood is equal to the string "Good"
so just pop mood == "Good" in there and the statement should be correct in terms of syntax, I don't know about the question itself yet as I haven't looked.
// this is correct
if(mood == "good" || mood == "Good")
EDIT: and after a closer look, avansc already solved this AGES ago, well I explained his reasoning anyway I guess
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
derbon wrote:if(mood == "good" || "Good") doesn't mean 'if your mood is good or Good". The || is used like if(condition ||condition). So you have to check "good" and "Good".
as far as i'm aware the latter part of the satement is wrong, mainly because you are evaluating whether the string "Good" is true or false, when you are supposed to be evaluating whether mood is equal to the string "Good"
I think what derbon was trying to say was that you need to evaluate two different conditions because he originally only had one. Not saying your explanation is wrong, but you're pretty much repeating what derbon just said.