I am having this problem with my code:
#include <iostream>
#include <vector>
#include <map>
using namespace std;
enum
{
DEATH,
ROOM1,
ROOM2,
ROOM3,
};
int main() {
int GameState = ROOM1;
int iRoomCounter[3] = {0,0,0}; // Used to determine if a room has been
visited.
string choice;
char Name[25];
cout << "!!!Hello World!!!" << endl;
cout << "Enter Your Name!" << endl;
cin >> Name;
cout << "Thank you " << Name << ". You will not be forgotten." << endl;
while(GameState != DEATH)
{
switch(GameState)
{
case ROOM1:
{
if (iRoomCounter[0] == 0) {
cout << "\n One day, " << Name << " was walking through a field and spotted a little Josiah." << endl;
cout << Name << " also spotted a cat. He wanted to pet both, but he could only pet one." << endl;
iRoomCounter[0] = 1;
}
cout << "\nWhich one will he pet?" << endl;
cout << "Josiah" << endl;
cout << "Cat" << endl;
cout << "-> ";
cin >> choice;
if(choice == "Josiah" || "josiah")
{
cout << "He pet Josiah" << endl;
GameState = ROOM1;
} else if(choice == "Cat" || "cat") {
cout << "He pet the Cat." << endl;
GameState = ROOM2;
} else if(choice == "Derp" || "derp")
{
cout << "Excuse me, but you are not following the rules." << endl;
cout << "Try again." << endl;
GameState = ROOM1;
}
else
{
cout << "I cannot recognize that word." << endl;
}
}break;
case ROOM2:
{
if(iRoomCounter[1] == 0)
{
cout << "\nAs you enter the room, you immediately notice a strange green glow" << endl;
cout << "coming from a decrepit alter in the center of the polished black " << endl;
cout << "floor. There is a slight stench of decay in the room. You also notice" << endl;
cout << "a faint hissing sound but you are not sure where it is coming from. You" << endl;
cout << "can see 2 doors leading out of this room. One is slightly ajar on the " << endl;
cout << "North wall and the other is closed tight along the South wall. " << endl;
cout << "you want to do?\n" << endl;
iRoomCounter[1] = 1;
}
}
return 0;
}
}
}
So here's the problem: As you can see in the code, when it asks what to pet, when I type in Cat, everything is fine and it moves on to the next part. But when I type in Derp, I want it to say "Excuse me, but you are not following the rules. Try again." And, when I type in anything besides Cat, it says "He pet Josiah." And, after it says "He pet Josiah", then I type in "Cat", it doesn't move on to the next part of the program. It only moves to the next part of the program if I type in "Cat" the first time it allows me to type something in. How do I make it so that when I type in Derp, it will have the text I want it to have, and I will still be able to continue on with the program?
Thanks in advance,
Ejay
Aucun commentaire:
Enregistrer un commentaire