mercredi 23 septembre 2020

This code is not working properly and it doesn't make any sense why it isn't to me. Does anyone have a guess what the problem might be? [closed]

This is the link to the hangman game in C++ I am making. It works perfectly fine on repl, but it doesn't work when I try to build and run it. It shoes letters have been guessed at the very start of the game, when which, obviously you haven't guessed any. The letters are also rather random having nothing to do with the game or anything, at least I think. Can someone else at least run this on their computer and see if it is just me? Thanks! It starts with:

WELCOME TO HANGMAN!!


----------------------------------------------------------------------------------------------------------

Here are the rules:
* you must enter one letter
* that letter cannot be a symbol
* you have ten guesses
* correct guesses won't count against you
* you cannot guess the same letter twice
* and finally, if you need to give up enter any numeral



You have 10 incorrect guesses left
The word so far is

_ _ _ _ _


You have guessed: A, B, I, J, K, Q, R, T,
What is your guess?

This is what is does give when first opened, however, I want it to show that you haven't guessed anything yet, because you haven't.

cout << "You have " << guesses << " incorrect guesses left" << endl;
    cout << "The word so far is\n\n";
    for (int i = 0; i < word.length(); i++)
    {
      if (i == word.length() - 1)
      {
        cout << guessedWord[i] << endl;
      }
      else
      {
        cout << guessedWord[i] << " ";
      }
    }
    cout << "\n\nYou have guessed: ";
    for (int i = 0; i < guessed.size(); ++i)
    {
      if (guessed[i])
      {
        cout << static_cast<char>(i + 'A') << ", ";
      }
    }
    cout << "\nWhat is your guess?" << endl;
    cin >> myGuess;
    istringstream myGuess2(myGuess);
    char guess = toupper(myGuess2.peek());
    if (isalpha(guess) == false)
    {
      if (isdigit(guess) == true)
      {
        break;
      }
      else
      {
        cout << "That is not a letter, please try again" << endl;
        continue;
      }
    }
    else if (guessed[guess - 'A'])
    {
      cout << "You have already guessed this." << endl;
      continue;
    }

This is what that part of it looks like, if none of the conditions by which you want to give up (if you enter a number) or if you do not enter an actual alphabetical character, then it goes on to take the ascii value of you guess, subtract the ascii value of 'A' to get the place of the letter in the array of bools, then it sets that letter's value to true. After it just checks if your guess is correct and everything, but that works fine for now.




Aucun commentaire:

Enregistrer un commentaire