Stuck on hangman

This is a discussion on Stuck on hangman within the C++ Programming forums, part of the General Programming Boards category; I am coding hangman for a project. My teacher supplied us with this code: Code: string show_hidden_letter(string secret, string hidden, ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    Stuck on hangman

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

    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
    Posts
    7,338
    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, 02:20 AM
  3. Program stuck in infinite loop-->PLEASE HELP
    By Jedijacob in forum C Programming
    Replies: 5
    Last Post: 03-26-2005, 11:40 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21