If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

String if statements?

I am very new at programming with C++. I am taking a class on it and I want to wow my teacher for an A. I am writing a simple textual input/output program and I want to know how I would do this part of it.

int main ()
{
string a;
cout << "type Yes or No" << "\n";
cin >> a;
if (a == "Yes")
{
cout << "textline one";
}
else
{
cout << "textline two";
}
}
I thought that this made sense, but for some reason it does not work. My program simply prints "textline one" whether the input was Yes or No. Can anyone explain this for me??
Thank you in advance for any help you provide.

Re: String if statements?

It is a matter of simple courtesy, and is well explained in the FAQ's (especially the "BEFORE you post" FAQ which is displayed at the top of each forum.

Please go back and EDIT your existing posts before further posting.

Also (and this is in the FAQ too!) you should enable private messaging to effectively communicate here on Code Guru.

TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009,2010In theory, there is no difference between theory and practice; in practice there is.

* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first

Gotta love the comma operator. It probably has mislead more novices than any other basic (not the language, just the level) operator....

TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009,2010In theory, there is no difference between theory and practice; in practice there is.

* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first

Re: String if statements?

Sorry again for the inconvenience guys. Thank you GCDEF, due to your reply I found that I must use if (a == "Yes" || a == "yes") in that format and the program now responds correctly... thank you all for the patience.

Re: String if statements?

Many people are in a hurry, remember that everyone here is volunteering their time here.

It is (almost) understandable that you may have skipped the FAQ before posting, but since you have been made aware of it, I cam curious why:

1) You have not edited your posts as requested.
2) You still have not enabled private messaging

A little consideration goes a long way when deciding which posts and posters) get the most attention from peoples limited time......

TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009,2010In theory, there is no difference between theory and practice; in practice there is.

* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first