0
I think with this game that when I make a mistake at the beginning of the game it tells me that a letter was wrong, but if you hit a letter and then make a mistake it doesn’t count. Help me.
Error: When I start the game asks for a word to be typed. If you miss the letters of that word when the game starts it counts, but if I hit a letter and miss again, the game stops counting the missing errors.
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
int main() {
char palavra[25],letra[25],lacuna[25];
int vida=6,x=0,i,total=0,cont=0;
printf(" ******************************");
printf("\n JOGO DA FORCA \n");
printf(" ******************************\n");
printf("\n BOM JOGO\n\n");
printf("\nDIGITE A PALAVRA E TECLE ENTER PARA CONTINUAR");
printf("\n\nPALAVRA: ");
gets(palavra);
fflush(stdin);
system("cls");
for(i=0;i<strlen(palavra);i++)
{
lacuna[i]='X';
total++;
cont++;
}
while(vida>0)
{
printf("\nA PALAVRA COMTEM %i LETRAS\n",total);
printf("\nLETRAS RESTANTES: %i\n",cont);
printf("\n%s\n",lacuna);
printf("\nENTRE COM UMA LETRA: ");
gets(letra);
system("cls");
for(i=0;i<strlen(palavra);i++)
{
if(letra[0]==palavra[i])
{
lacuna[i]=palavra[i];
x++;
cont--;
}
}
if(cont==0){
printf("PARABENS! VOCE VENCEU!");
printf("\nACERTOU A PALAVRA %s", palavra);
}
if(x==0)
{
vida--;
printf("\nVOCE PERDEU UMA VIDA!\nVOCE TEM %d VIDA(S) RESTANTES\n\n",vida);
}
}
printf("\n\nVC FOI ENFORCADO, Fim de jogo!\n\n\nPALAVRA SECRETA:
%s",palavra);
printf("\n\n***********************\n\n");
printf("* JOGO DA FORCA *\n\n");
printf(" ___ \n");
printf(" | | \n");
printf(" | O \n");
printf(" |/|\ \n");
printf(" | | \n");
printf(" |/ \ \n");
printf(" |______ \n");
printf("\n**********************\n");
getchar();
getchar();
return 0;
}
How so stop accounting for missing errors?
– Francisco
https://answall.com/q/95977/132
– Victor Stafusa
I suggest you replace
gets()
forfgets()
and look for viable library alternativesconio.h
. Doing what I recommended may not change much for this program, but it is always good to implement quality code, even in the simplest projects.– Nexus