Thread: A C++ program problem.

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    A C++ program problem.

    I got a homework assignment this week, but I don't really know how to do it. Can someone tell me what should I do for this program? Don't have to show me the program, I just want some hint for that. Like what kind of loops should I used, and I just don't really get this program... Please help me!!

    This program will play the game of "Hangman" - wherein the user tries to guess the proper letters forming a word selected by the computer, or by a second user. Each time an incorrect letter is chosen, a new portion of a hanged man is drawn - if the fully hanged man figure is drawn, the user has lost! If, on the other hand, the user guesses the word correctly before then, the user wins.

    1. The user should be able to choose between playing against the computer, or against another human. The only difference will be how the word to be guessed is selected: If playing against the computer, the computer will choose from a built-in list of words, picking one of them at random; If playing against another human, the human hangman will type in a word (a string)
    2. The user (either the guesser or the hangman) should be asked for the number of incorrect guesses to allow the guesser... within the range 4 to 10 inclusive.
    3. Before each guess entered by the user, the program should
    1. Display the letters already chosen
    2. Display the number of guesses left
    3. Display the portion of the word already guessed, inserting an * (asterisk) for each letter not yet guessed.
    4. (Optional) Display the hanged man portions already "drawn" - starting with a scaffold, then the head, body, arms, legs, face, etc...
    4. The user enters a character; the program will then indicate if an incorrect character was chosen:
    1. A letter already chosen
    2. Any non-alphabetic character (such as ?, /, 4, $, etc.) (Hint: see documentation on ctypes.h - especially isalpha())
    5. If the user has correctly guessed a letter that appears in the word, the displayed word (with asterisks) is updated, replacing the proper asterisks with the correctly guessed letter. For example, if the word were "EAGLE" and the user guessed "E", both the first and last letters would be filled in : E***E.
    6. If the user has correctly guessed the entire word without using all of the allowed incorrect guesses, a congratulatory message (and, optionally, bells and whistles!) Should be displayed. If, on the other hand, the user runs out of incorrect guesses, an appropriate message of condolence should be displayed.
    7. Upon termination of a game the program should prompt the player if another game is wanted - an 'n' or 'N' will terminate the program, otherwise it will loop back, select another word, and do it all again!!

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Draw a flowchart first. After that, it usually becomes easier to see how to put the logic together.
    You can also translate that to pseudo code, and then translate it to code.
    This is my hint to you. If you fail to understand how to translate the flowchart into code, then I would offer further assistance there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:34 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. Replies: 20
    Last Post: 06-12-2005, 11:53 PM