So this is a part of my code. When I press '1' it should enter the case 1: in the switch, but it doesnt.. I can press 2 and 3. How come, what's going wrong?
void playGame()
{
bool runGame = true;
int guesses = 10;
int guessCount = 0;
int position;
int wrongGuesses = 0;
std::string word = randomWord();
std::string correctWord;
std::string guessed;
std::string guess;
for (int i = 0; i < word.length(); i++)
{
correctWord.insert(i, "_");
}
while (runGame)
{
std::cout << "Welcome to hangman! Don't just hang there, go guess!\n\n\n";
std::cout << "GUESSES LEFT: " << guesses << std::endl;
std::cout << "Pleae guess a letter or full word\n\n";
std::cout << "Letters you have guessed already: " << guessed << std::endl;
std::cout << std::endl << correctWord << std::endl << std::endl << "Next letter or full word: ";
std::cin >> guess;
guessed.insert(guessCount,guess);
guessCount++;
position = word.find(guess);
if (word == guess)//om man gissar rätt ord genom att skriva hela
{
std::cout << "Correct guess, you won!\n";
runGame = false;
}
elseif (word.find(guess) != std::string::npos)//om gissningen finns med i det rätta ordet
{
correctWord[position] = word[position];
for (int j = 0; j < word.length(); j++)//går igenom hela ordet med gissningen och ändrar om man gissat något rätt
{
if(guess[0] == word[j])
{
correctWord[j] = guess[0];
}
}
system("cls");
if (correctWord == word)
{
std::cout << "Correct word, you won.\n";
runGame = false;
}
}
else
{
guesses-=1;
wrongGuesses++;
system("cls");
}
if (guesses == 0) //om man får slut på chanser
{
runGame = false;
}
}
}