Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,143 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,059 people online right now. Registration is fast and FREE... Join Now!




Illegal Comparison

 
Reply to this topicStart new topic

Illegal Comparison, Help with asking about food.

wmiii923
25 Feb, 2007 - 12:11 PM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2006
Posts: 7


My Contributions
I can't get this to work, I've googled it, searched this site, and even asked some friends. I get this error:
CODE
ISO C++ forbids comparison between pointer and integer

When I try to compile this code:
CODE
#include <stdio.h>
char answer();
main(){

       printf("\n Press ENTER or RETURN to continue.");
       getchar();
       printf("What do you like to eat? ");
       printf("\n a)television sets");
       printf("\n b)potatoes");
       printf("\n c)cheese");
       printf("\n d)pie");
       printf("\n \n");
       printf("What is your answer? \n");
       scanf("%c", &answer);
       getchar();
       if(answer == 'c'){
       printf("correct");
}
getchar();
       }



This post has been edited by Videege: 25 Feb, 2007 - 12:19 PM
User is offlineProfile CardPM
+Quote Post

Craige
RE: Illegal Comparison
25 Feb, 2007 - 12:22 PM
Post #2

D.I.C Head
**

Joined: 2 Nov, 2006
Posts: 63


My Contributions
This:
CODE

if(answer == 'c'){


Should be:
CODE

if(*answer == 'c'){

User is offlineProfile CardPM
+Quote Post

wmiii923
RE: Illegal Comparison
25 Feb, 2007 - 12:24 PM
Post #3

New D.I.C Head
*

Joined: 15 Sep, 2006
Posts: 7


My Contributions
QUOTE(Craige @ 25 Feb, 2007 - 01:22 PM) *

This:
CODE

if(answer == 'c'){


Should be:
CODE

if(*answer == 'c'){


Sorry, still get the same error.
Could it be my compiler?
User is offlineProfile CardPM
+Quote Post

Craige
RE: Illegal Comparison
25 Feb, 2007 - 12:37 PM
Post #4

D.I.C Head
**

Joined: 2 Nov, 2006
Posts: 63


My Contributions
Ah wait, its this line:

CODE

char answer();


Remove the brackets.
User is offlineProfile CardPM
+Quote Post

wmiii923
RE: Illegal Comparison
25 Feb, 2007 - 12:45 PM
Post #5

New D.I.C Head
*

Joined: 15 Sep, 2006
Posts: 7


My Contributions
Thanks alot.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:43PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month