sean

sean

  • NA
  • 3
  • 0

Using a foreach loop strings and char

Feb 6 2008 1:42 PM

I'm supposed to be making a wheel of fortune type game for a project. One character is typed into the guess box and that value is saved as "char guess;" The foreach loop is supposed to move through the mysteryPhrase trying to match the player's guess to the a matching character. Here arethe instructions:

For each character in the mysteryPhrase, if the guess matches character, then append the guess to the newDisplayedPhrase. Otherwise append the character in the matching location of the old displayedphrase to the newDisplayed phrase.

(Hint, you will need an integer variable, location. It will be declared and initialized to zero outside the loop. It will also need to be incremented on every pass through the loop)

If you guys need any more info just let me know. I just need some help getting started here.

I used

foreach(char next in mysteryphrase)

     if(char == guess)

The if statement didn't work. I also tried

if(char.Equals(guess))

But that wasn't quite right either. I really appreciate the help guys.

 


Answers (2)