So i'm making a text adventure game i'm just programming directions. I have a script with north south etc. And then an if statement that says if the user enters something other than a direction it will say that is not a direction and loop to the top but its not working. It will always print That is not a direction even if I enter the right input. Can anyone help?
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string input;
while (input != "north", "n", "south", "s", "east", "e") {
cout << "Enter a direction" << endl;
getline(cin, input);
if (input == "north" || input == "n") {
cout << "north" << endl;
}
if (input == "west" || input == "w") {
cout << "west" << endl;
}
if (input == "east" || input == "e") {
cout << "east" << endl;
}
if (input == "south" || input == "s") {
cout << "south" << endl;
}
if (input != "n", "s", "e", "w")
{
cout << "That is not a direction" << endl;
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire