if statements on parts of a string

Hi, can someone help, I want to write "if statements" on parts of a string and I am not having any success. Here is some sample code to show you what i mean.
Thanks


{
string day ;
cout << "What day is it? " << endl ;
getline(cin, day) ;
if (day[0] == "s" || day[0] == "S" )
{
cout << "Sorry i don’t work on Saturdays of Sundays" ;
}
}

or

{
string day ;
cout << "What day is it? " << endl ;
cin >> day ;
if (day[0] == "s" || day[0] == "S" )
{
cout << "Sorry i don’t work on Saturdays of Sundays" ;
}
}

Last edited on
closed account (E0p9LyTq)
Change
if (day[0] == "s" || day[0] == "S" )

to
if (day[0] == 's' || day[0] == 'S')

And in the future please use code tags for properly formatting your source.

http://www.cplusplus.com/articles/z13hAqkS/
closed account (E0p9LyTq)
If you want to get really "fancy" change the if statement to:

if (toupper(day[0]) == 'S')

or

if (tolower(day[0]) == 's')

http://www.cplusplus.com/reference/cctype/toupper/
http://www.cplusplus.com/reference/cctype/tolower/
Last edited on
Perfect, thanks FurryGuy.
Sorry about the lack of code tags
Topic archived. No new replies allowed.