Solved Please guys help me with this code c++

September 30, 2012 at 06:28:10
Specs: windows xp prof, 192 mb anthlon 600mhz
Here is my code my problem is that the if statement will evaluate false even when i enteq biology
#include <iostream.h>
int main()
{
char keyword[80];
cout << "Please enter the word and press Enter: ";
cin.getline(keyword,80);
cout << "you entered " << keyword <<"\n";

if (keyword == "biology")
cout <<"The study of living things ";
else
cout <<"The keyword couldn't be found \n";




return 0;
}

See More: Please guys help me with this code c++

Report •


#1
September 30, 2012 at 07:24:21
✔ Best Answer
You can't use == with a character-array string. Either use strcmp() or else use a proper string class.

Report •

#2
September 30, 2012 at 09:42:46
@ijack i know that would be a better idea but can't figure out how please can u copy my code make the changes and post so i can get u

Report •

#3
September 30, 2012 at 10:21:55
Sorry, I don't do homework. I've explained what you are doing wrong; now it's up to you to use that information to research the solution. You'll learn more that way than if I do it for you.

Report •

Related Solutions

#4
October 1, 2012 at 16:13:30
Yes it worked the string compare just did the job thanks dude

Report •

Ask Question