when i always run the program then started to input a correct letter, the total_tries always trigger to decrements by 1 and when i am going to input a wrong letter it is decrements by 2...i cant find what is the problem. can anyone help me for my problem? thanks alot, sorry for the long code...
Code:gotoxy(1,3); printf("enter a word: \n"); do{ c=getch(); switch(c) { case '\r': break; case '\b': printf("\b \b"); --x; break; default: printf("%c", '*'); word[x++]=c; break; } }while(c != '\r'); word[x]='\0'; clrscr(); length=strlen(word); for(i=0;i<length;i++) { undscr[i]='_'; } while(!done&&total_tries>0) { printf("\n\ntries left: %d", total_tries); if(total_tries==7) { printf("\n\t\t_______\n\t\t| |\n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==6) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==5) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| T\n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==4) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| |T\n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==3) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| |T|\n\t\t| \n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==2) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| |T|\n\t\t| /\n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } else if(total_tries==1) { printf("\n\t\t_______\n\t\t| |\n\t\t| O \n\t\t| |T|\n\t\t| //\n\t\t| \n\t\t| \n\t\t| \n\t _|_\n\t /___|"); } gotoxy(1,15); for(i=0;i<length;i++) { printf("%c ", undscr[i]); } if(good>=length) { done=1; break; } do{ printf("\n\n\n\nguess a letter: "); letter=getchar(); for(i=0;i<length;i++) { if(letter==word[i]) { undscr[i]=word[i]; good++; disc=1; } clrscr(); } if(disc==0) { total_tries--; } disc=0; } while(i!=length && disc!=0); } if(done) gotoxy(1,20); printf("You guessed it!\n\n"); printf("Hit Enter to exit\n"); getch(); return 0; }



LinkBack URL
About LinkBacks



