--- In [email protected], "len_kim" <[EMAIL PROTECTED]> wrote:
>
> Hello, 
> 
> I am brand new to programming and am currently attempting to learn 
> C++. 
> I am unable to get the below program to evaluate the string that is 
> entered for the name. Can someone tell me what I am doing wrong and 
> if it is even possible to run an "if" statement and make it evaluate 
> a string? 
> 
> #include <iostream>
> #include <string>
> using namespace std;
> int main()
> { string name;
> cout << "Please enter your name ";
> cin >> name;
> if (name == 'John')
> cout << "Your name is John ";
> else
> cout << "Your name is not John ";
> return 0;
> }
>


using C++...

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s_name;
    cout << "Please enter your name:";
    getline (cin, s_name);
    if (!s_name.compare ("John")) {
        cout << "Your name is John";
    }
    else {
        cout << "Your name is not John";
    }
    return 0;
}


Reply via email to