while (true) {

		// Display the players location and possible movements.

		cout << "------------------" << endl;
		cout << "Location:   " << NewUser.location->name << endl;
		cout << "\nDescription:   " << NewUser.location->description << endl;
		if (NewUser.location->north)
			cout << "(N)orth to: " << NewUser.location->north->name << endl;
		if (NewUser.location->south)
			cout << "(S)outh to: " << NewUser.location->south->name << endl;
		if (NewUser.location->east)
			cout << "(E)ast to:  " << NewUser.location->east->name << endl;
		if (NewUser.location->west)
			cout << "(W)est to:  " << NewUser.location->west->name << endl;
		cout << "(Q)uit" << endl;

		// Get input and decide where to go next.

		char input;
		cin >> input;
		if (input == 'n' && NewUser.location->north)
			NewUser.location = NewUser.location->north;
		if (input == 's' && NewUser.location->south)

                cout << quizMaster.poseQuestion().c_str() << endl;
                getline(cin, answer);

            if (quizMaster.isCorrectAnswer(answer))
                cout << "Thats right" << endl;
            else
                cout << "Better luck next time !" << endl;

			NewUser.location = NewUser.location->south;

		if (input == 'e' && NewUser.location->east)
			NewUser.location = NewUser.location->east;
		if (input == 'w' && NewUser.location->west)
			NewUser.location = NewUser.location->west;
		if (input == 'q')
			break;
	}

	delete [] rooms;

Here is my loop.

Now if I put

cout << quizMaster.poseQuestion().c_str() << endl;
                getline(cin, answer);

            if (quizMaster.isCorrectAnswer(answer))
                cout << "Thats right" << endl;
            else
                cout << "Better luck next time !" << endl;

This in all of the other directions, it gets stuck saying better luck next time and then exe freezes and closes.

I have the full code which relates to the above as a attatchement.

Any Ideas?

Thanks in advance.

Member Avatar for jencas

Did you try to debug step by step?

It must mean that quizMaster.isCorrectAnswer(answer) is always returning 0 .Just check in that particular function for solving the problem. Its quite straight forward right.

Hey guys, sorry I have been quite busy and over the course of the week I have re worked my logic.

I now have

// Get input and decide where to go next.

		char input;
		cin >> input;

		if (input == 'q')
			break;

                cout << quizMaster.poseQuestion().c_str() << endl;
                getline(cin, answer);

		if (quizMaster.isCorrectAnswer(answer)) {
                	cout << "Thats right" << endl;

			if (input == 'n' && NewUser.location->north)
				NewUser.location = NewUser.location->north;
			if (input == 's' && NewUser.location->south)
				NewUser.location = NewUser.location->south;
			if (input == 'e' && NewUser.location->east)
				NewUser.location = NewUser.location->east;
			if (input == 'w' && NewUser.location->west)
				NewUser.location = NewUser.location->west;

		} else {
                	cout << "Better luck next time !" << endl;
		}

Except is always ignores the cin >> input it always goes stright to better lucknext tiem, then displays the area again, so it ignores the NewUser.location-> Whichever.

I think ive sorted it,

I have to take the input as a string parse it to 1 character and then put that input back into the char value,

that way the buffer will be cleared and it wont go to false

hah

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.