[Solved] Hangman – How to properly count the player wrong guesses? [closed]


The problem was the way you were trying to increase incorrect.
Just use wrong as a boolean that you will use to decide if you need to increase or not incorrect

Here’s the solution:

#include <stdio.h>
#include <string.h>
#define SIZE 50

/*prototype definitions*/
int compareString(char *, char *);

int main(void){

  char word[SIZE];
  char input[SIZE];
  char guess[SIZE];
  int count = 0;
  int wrong = 1;
  int incorrect = 0;
  int right = 0;
  int len = 0;

  printf("Please enter the word you would like to have to guess.\nThen hand your computer over to the person you would like to have play:");
  fgets(word, SIZE, stdin);

  len = strlen(word);

  printf("Please guess one letter for the %d letter word!\n", len - 1);

  do{

    fgets(input, SIZE, stdin);
    wrong = 1;
    for(count = 0; count < len - 1; count++){

      if(input[0] == word[count]){
        printf("that letter is in the %d spot\n", count + 1);
        wrong = 0;
        ++right;
      }
      /*I know the problem lies here but i'm not sure how to fix it I've tried not using len-1         and just using len, I've tried not resetting the amount wrong. Everything!*/
    }
    if(wrong) {
      incorrect++;
    }

  }while(incorrect < 6 && right < len - 1);


  return 0;
}

4

solved Hangman – How to properly count the player wrong guesses? [closed]