class theGame
{
private:
void question1();//You awake
void question2();//Go find a sword
void question3();//Go find armor
void question4();//Find dragon
void question5();//Kill dragon
char answer1; 
char answer2;
char answer3;
char answer4;
char answer5;


public:
void showQuestion();
void enterAnswer();

};

void theGame::showQuestion()
{
void question1();
void questoin2();
void question3();
void question4();
void question5();
}

void theGame::question1()
{
	int right;
cout<<"You awake and get out of bed and realize that you want to go kill a dragon for no reason. Now what? ";
cin >> answer1;
if (answer1 == 'Leave')
	right = 1;
else
	right = 0;

while(right = 0)
{
cout << "That doesn't work. Try again... " << endl;
cin >> answer1;

if (answer1 == "Leave")
	right = 1;
else
	right = 0;
}
if (right = 1)
cout<<"You leave your house and now you need to find a sword. " << endl;
	
}

Error: error C2446: '==' : no conversion from 'const char *' to 'int'

Basicaly I'm making a VERY simple text based adventure game, I am probably doing it all wrong, and I'm using Visual C++ 2008. Also if you could tell me how to find a word in a sentence the user will enter that would be nice too. Thanks! Question 2 - 5 are basically just a copy and past of Question1.

Recommended Answers

All 2 Replies

>>if (answer1 == 'Leave')

answer1 is just a single character and you are attempting to compare it, illegally by the way, to a string. You need to make answer1 a character array and use strcmp() to compare it to a string. Or you could make answer1 a std::string object, since this is c++. Note the double quotes around "Leave".

std::string answer1;

...
cout<<"You awake and get out of bed and realize that you want to go kill a dragon for no reason. Now what? ";
cin >> answer1;
if (answer1 == "Leave")
	right = 1;
else
	right = 0;

A couple of other things too:

As mentioned above, this is an illegal comparison:

if (answer1 == 'Leave')
	right = 1;
else
	right = 0;

To make that cleaner you can use a couple of methods (assuming 'answer1' is now the correct type): right=(answer1 == "Leave"); as the conditional returns 1 if it's true, 0 if it's false. right=(answer1 == "Leave")? 1 : 0; the ternary operator

or probably easiest to read and least bug-prone:

if (answer1 == "Leave")
{
	right = 1;
}else{
	right = 0;
}

Below, '=' is an assignment operator, '==' is a comparison operator. You are assigning the value 0 to right.

while(right = 0)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.