Hangman
|
|||
|
Rank: ? (4)
Member #: 27545 |
Can you help me with this problem??
Instead of drawing a hangman, it will output the word "B I T A Y". Five mistakes only. Whenever you commit a mistake, it will gradually spell out "BITAY" BITAY is a visayan word for hang. here is the codes: (to be modify) #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> void main() { char answer[20],*pointer=NULL; int i=0,ch=0,lives=5,found,len=0; char clue[50]; char re; do { clrscr(); printf("Enter clue (for your answer):\n"; scanf("%s",&clue); gets(clue); printf("\n"; printf("Enter your answer:\n"; gets(answer); { clrscr(); } printf("HENCE: Five mistakes only, else BITAY!\n\n"; printf("\nType only one letter at a time\n\n"; printf("CLUE: %s\n\n",&clue); //system("CLS"; len=strlen(answer); pointer=realloc(pointer,(len+1)*sizeof(char)); // if(pointer==NULL) // { // printf("Realloc failed\n"; // exit(1); // } for(i=0;i<len;i++) pointer[i]='-'; pointer[i]='\0'; while(lives>0) { // system("CLS"; found=0; printf("%s\n\n",pointer); ch=getchar(); for(i=0;i<len;i++) { if(ch==answer[i]) { pointer[i]=(char)ch; found=1; } } if(found==0) lives--; if(strcmp(pointer,answer)==0) { // system("CLS"; printf("You win!\n"; printf("The word was %s: \n",answer); printf("Do you want to win again? [Y/N]? "; scanf("\n%c",&re); free(pointer); } } //system("CLS"; printf("You loose!\n"; printf("The word was : %s\n",answer); printf("Do you want to loose again? [Y/N]? "; scanf("\n%c",&re); free(pointer); } while(re=='Y'||re=='y'); getch(); } here, also the sample program: #include<stdio.h> #include<conio.h> void main() { char w[]={'H','E','L','L','O'}; char b[]={'B','I','T','A','Y'}; char c; int ctr; int lives = 5; int flag; int i=1; int correct=0; int bit=-1; char a; do { lives = 5; i=1; correct=0; bit=-1; clrscr(); gotoxy(10,9); cprintf("WHAT'S THE WORD? THAT'S THE WORD!"; gotoxy(10,10); cprintf("Clue: Greetings!"; gotoxy(10, 12); cprintf("_____"; while (lives >= 1 && correct!=5) { flag=0; gotoxy(10,5); cprintf("GUESS (%d)-> ",i++); scanf("\n%c",&c); c=toupper(c); for(ctr=0;ctr<5;ctr++) { if(c==w[ctr]) { gotoxy(10+ctr, 12); cprintf("%c",w[ctr]); flag=1; correct++; } if(ctr==4&&flag==0) { lives--; bit++; gotoxy(40+bit,6); cprintf("%c",b[bit]); gotoxy(40,5); cprintf("REMAINING LIVES: %d",lives); } } } if (correct == 5) { gotoxy(10, 15); cprintf("CONGRATULATIONS!!!"; } else { gotoxy(10, 15); cprintf("SORRY YOU LOSE!"; } gotoxy(10, 16); cprintf("TRY AGAIN?(Y/N) -> "; scanf("\n%c",&a); a=toupper(a); } while(a=='Y'); getch(); } Thanks, john |
||
|
Please login or register to post a reply.