Question:

C++ error: pointer - integer conversion error.?

by  |  earlier

0 LIKES UnLike

Hi

Actually I fixed those, now I have a new problem. I keep getting a "forbids comparison between pointer and integer" error for lines 39, 45, 51, and 57. Here's the updated version.

// enter the attack value of your character

int attack;

cout << "Enter the base Attack Value of your character:";

cin >> attack;

// define the possible integer values for the different

// creature name types entered

int nRobot;

nRobot = 50;

int nAnimal;

nAnimal = 40;

int nHumanoid;

nHumanoid = 40;

int nMonster;

nMonster = 70;

// enter the base health of the enemy creature

char type;

cout << "Enter the name of the enemy character type in all lowercase:";

cin >> type;

// define the type value depending on the creature type

int health;

if (type == "monster")

{

health = nMonster;

}

else

{

if (type == "animal")

{

health = nAnimal;

}

else

{

if (type == "humanoid")

{

health = nHumanoid;

}

else

{

if (type == "robot")

{

health = nRobot;

}

 Tags:

   Report

1 ANSWERS


  1. You can&#039;t compare two strings using &quot;==&quot;, you need to use e.g. the strcmp/strcasecmp functions.

    &quot;foo&quot; in a comparison is really a pointer to the string.

    Also, you defined your input as &quot;char type&quot; which is only a single character, you probably meant for it to be a string (char*).

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.