Hangman Game iterating over arrays with the for loop in C# -


so, earlier posted question asking how run string through character array make each letter equal separate character value in array.

i tried using foreach loop , labeling each object in array "guess" , testing every value against user-inputted value, couldn't figure out how output @ end of loop if user inputted false value. instead of outputting every time value false against array values since loop designed every value.

so i'm kind of stuck. think there way loop i'm still kind of noobish. wondering if me please.

        char letter;         int score = 0;         string hangword;          //input inputs         console.writeline("welcome hangman game!");         console.writeline();         console.writeline();         console.writeline();         console.writeline("player 1 please enter word.");         hangword = convert.tostring(console.readline());         char[] hangcharacters = hangword.tochararray();         char[] asteriskword = hangword.tochararray();         string displayword;          foreach (char guess in asteriskword)         {             asteriskword[guess] = '*';         }         while (score < 5)         {             console.writeline("enter letter please");              console.writeline();             foreach (char guess in hangcharacters)             {                //how write loop tests values , if none correct                              //displays "you guessed incorrectly"?                 letter = convert.tochar(console.readline());                 if( guess == letter)                 {                     console.writeline("you guessed correctly!");                     console.writeline                         //also don't know how change correct value      in asteriskword[] displays                         //only character guessed in asteriskword[]                 }              }         }         console.writeline("your score " + score);         if (displayword == hangword)             console.writeline("you win! thank playing!");         else         {             console.writeline("thank playing! try again!");         } 

before foreach take bool flag false, make true inside foreach if letter matches, otherwise remain false. test condition after iterations , display message according flag state.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -