this runs but with unexpected results,why?I insist on using cin.getline
and I was hoping if statement will execute, however the else statement is da one dat executes.
As for the question I think the first answer is correct

char name[256];

cout <<"enter name"<<endl;

cin.getline(name, 256);

if (name == "My boy")

cout <<"Hello, My boy!"<<endl;

else

cout <<"Hello, My Girl"<<endl;

You cant compare char strings like that. You have to use the strcmp() function. I you want to compare strings with the logical comparison operator than you could use the string class available from <string> or you have to write your own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.