Thread: Stuck on hangman

  1. #1
    Registered User
    Join Date
    Oct 2010

    Stuck on hangman

    I am coding hangman for a project. My teacher supplied us with this code:

    string show_hidden_letter(string secret, string hidden, char guess)
    string result = hidden;
    for (unsigned i = 0; i < result.length(); i++)
    if (secret[i] == guess)
    result[i] = guess;
    return result;
    It is suppose to return the hidden word with the correct words the player guessed revealed.

    Now what I am stuck on is how to use this function. I have declared the prototype at the top already and have the function underneath the int main.

    How do we use this function in int main?

    I am the random word picked by the computer as "word", the word replaced with stars as "secret", and the letter chose by the person as "a".

    So I know it involves something like this in the int main:
    show_hidden_letter(word, secret, a) but I don't know how to use it nor how to cout the new updated version where the correct letter is revealed.

    Please help me with this. I am not looking to be spoon fed but is willing to learn how to use this function properly. Thank you in advance.

  2. #2
    Registered User
    Join Date
    Jan 2005
    The function returns a string. How do you get that string from the function? What should you do with it after you get it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-23-2006, 07:22 PM
  2. Hangman Game - Part 2
    By tigrfire in forum C Programming
    Replies: 1
    Last Post: 11-28-2005, 03:20 AM
  3. Program stuck in infinite loop-->PLEASE HELP
    By Jedijacob in forum C Programming
    Replies: 5
    Last Post: 03-26-2005, 12:40 PM
  4. Help doing Hangman...
    By Kreative in forum C Programming
    Replies: 11
    Last Post: 08-18-2002, 09:22 PM
  5. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM