Transposing string

Hello guys,

can some please give driection as to how to archieve this big issue i am having:

I a random number that has been generated and wants the user to guess it, let me illustrate this:

say the random i hve generated is 'nice'

  • i then hide it from the user and display it in ----
    -but now if the use enter 'n' because it is in the random word, i would then display to them n---
    and so until they get all the letters

i have used a while loop, but i seem to be loosing previously guessed letters

This sounds a lot like homework. The forum explicitly bans homework.

my apologies, its not an home, its an element of a project i am working, though its work based. I was just asking for a guidance

# pseudo code

random_word=`generate_random_word`
guessed_letters=`echo $random_word | sed -e 's/./-/gp'`
guesses=0
max_guesses=26

while ( $random_word != $guessed_letters  && $guesses < $max_guesses ) {
  # If the input can be found in $random_word, 
  #   replace the same position  in $guessed_letters with that input. 
  # 
  # ++$guesses

  print $guessed_letters
}