Ask coding questions

← Back to all posts
What am I doing wrong...
ohsoodelicious (0)

I just need the condition to compile correctly.. Its SUPPOSED to give a message if the user enters the wrong animal. Cat or Dog. If the user enters anything other than cat or dog, it will say only cats or dogs need tags. Instead , if you enter cat or dog it still gives the you the message with the complete program... Just a straight answer is all I need. Where does the condition belong to compile correctly.

Answered by Coder100 (8404) [earned 5 cycles]
View Answer
Commentshotnewtop
Coder100 (8404)

Oops, I made a mistake, I thought strcmp worked for C++, turns out that isn't the case, well anyways, it was just a logic thing:

if (pet == "cat" && pet == "dog")
   {
      cout << "Only cats and dogs need pet tags. \n";
   }
Coder100 (8404)

Strings cannot be compared using ==

You will have to use strcmp

if (strcmp(pet, "cat") == 0 && strcmp(pet, "dog") == 0)
   {
      cout << "Only cats and dogs need pet tags. \n";
   }

Also, use && because if the value was cat it can't be dog so then the second part (comparing to dog) would be true and so that statement would always be false.

Summit (13)

@coder100 nevermind just saw your other post

Coder100 (8404)

hm, C is getting worse and worse @Summit

Summit (13)

@Coder100 why? ik in java u cant compare strings i think.