jeudi 23 janvier 2020

Comparison between pointer and integer C++ forbidden

Hey so i'm still learning C++ and i've ran into a snag while compiling this part of my code. Before i go any further with the text game that I'm developing for a project i'd like to know why I am getting this error when attempting to compile so I can debug as I develop.

ISO C++ forbids comparison between pointer and integer [-fpermissive] if (answer1 == 'Yes' && answer1 == 'yes) {

I'm not exactly sure where i am going wrong because the code is storing the result as "Yes". (I checked by adding a std::cout >> answer1; after gathering the users y/n answer.)

but when i try to check that with the If statement i get this error.

    #include <iostream>

int main() {

  char name[50];
  char answer1[50];

  std::cout << "Ahh... Welcome newcomer. What is your name?\n";
  std::cin >> name;
  std::cout << "You said your name was " << name << " correct?\n";
  std::cin >> answer1;

    // Let the game begin!

  if (answer1 == 'Yes' && answer1 == 'yes') {

    std::cout << "Lets get this game started then!\n";

  }
  else {

    std::cout << "Then why are you even wasting my time?\n";
  }

}

I know it's basic and rudimentary but I am still learning (self-taught, too). Thanks for reading.

Aucun commentaire:

Enregistrer un commentaire