delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/04/02:46:28

From: "Matt Kris" <jdkris AT NOPOOPalpha DOT delta DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Loop help
Date: Tue, 3 Mar 1998 23:16:23 -0500
Organization: Delta College
Lines: 41
Message-ID: <6dikoa$gel@alpha.delta.edu>
NNTP-Posting-Host: pm090-06.dialip.mich.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I know this isn't a DJGPP question but I dunno the C group.

I am trying to start on a Hangman game.  Not I have no idea why this won't
work.  It's suppose to take a word that is stored in an array and check if
the guess matches any of the letters in the word.  I had it working once but
I changed something and don't remember what!!  Please take a look.

int turns=6;                             /* Number of turns before man is
dead */
char word[25]="monkey";    /* The actual word */
int length=6;                          /* The length of the word */
int counter;                            /* The counter */
char guess;                          /* Holds the guesses */

main()
{


/*  The hard part that needs worked on */

 while(turns>0)
   {
     printf("\nYou have %d turns left\n", turns);
     printf("\nGuess? ");
     scanf("%c", guess);
     for(counter=length;counter>0;counter--)
       {
         if(guess==word[counter])
           {
             printf("You got one\n");
             printf("You got %c", word[counter]);
             turns++;
           }
       }
     turns--;
   }
 return 0;
}



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019