Forbid comparison between pointer and integer

November 26, 2011 at 11:43:41
Specs: Windows 7 Ultimate, Core 2 Duo 2.4GHz / 3 gigs
I am new to the world of programming and I'm just learning how to program in C++ and I can't figure out what I'm doing wrong. Any help would be nice. This is the basic structure and i get an error the line: if (answer=='yes') The error is: ISO C++ forbids comparison between pointer and integer. What am I doing wrong/ How do i fix it? Thank you.

#include <iostream>

using namespace std;

int main()
char question[] = "Do you like pancakes? Yes or No? ";
char pos_response[] = "Oh, me too!";
char neg_response[] = "Yeah, me either.";
char answer[3];

cout << question;
cin >> answer;

if (answer=='yes')
cout << pos_response;

See More: Forbid comparison between pointer and integer

Report •

November 26, 2011 at 13:13:57
You can't compare strings with the == operator. Use the strcmp() function from the Standard Library.

Report •

November 26, 2011 at 16:24:13
Just for clarification, you can't compare cstrings with the operator==. std::string does have its set of comparison operators, including ==. Consider this yet another reason to use std::string over arrays of chars. Additionally, single quotes are for single characters; double quotes are for a series of characters.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question