Results 1 to 8 of 8

Thread: Beginner needs help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Angry

    I have a homework assignment due tonight;

    I need to write a program in C++ with the following:

    Hangman Game

    It has to have 2 parallel arrays, One named Word, which will store the word entered by a user.

    The second array will be called Guesses, will store a corisponding dash (-) for each letter in the word.

    with each correct guess the (Hyphen) will be replaced by the letter.

    Both the Guess and the word array will need to be 6 element Character arrays.

    Now I fumbled my way through the simple array project, and this is my last problem, and I really need help. The book isn't really clear. I just want to finish the class and move on, it was required. I have no plans on writing in C++, I am O.K. with VB.


    Help! I really need to get it done, and I have NO CLUE!
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  2. #2
    Guest
    Well, I don't think people on here would do your assignment for you, but we'd be glad to help where ever you are having trouble. What are you stuck on right now?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    I wasn't looking for that. I am confused on the parallel array and how to even begin writing it
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  4. #4
    Guest
    Code:
    char cWord[5];  // 6 elements including 0
    char cUnderscores[5];
    
    cWord = "Myword";
    cUnderscores = "_____";

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    Never mind.
    I know how to initialize the array.
    I needed some insights on how the parallel arrays work.

    I will look elsewhere.
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Talking

    Megatron,
    First off let me say I didn't mean to sound like a dick.

    After the quake scrambled my hard drive, let's just say I was in poor spirits.

    I got the assignment done, and still have no clue how I did it.

    Things here in Seattle have been a little hectic lately.

    I hope you were not offended, (for too long).
    Lee
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  7. #7
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You need to declare the char array with a size equal to the number of characters you want in your string, plus 1 for the end of string character ('\0'). You also can't just assign string literals to char arrays (a string literal like "Myword" in your code is basically a pointer to that string in the .exe), you need to use the strcpy() function to copy them over.

    Code:
    char cWord[7];  // 6 elements plus the '\0'
    char cUnderscores[7];
    
    strcpy(cWord, "Myword");
    strcpy(cUnderscores, "_____");
    I think the idea with the parallel arrays is that when a user guesses a letter, you can loop through your arrays and check in the cWord[] array whether that letter occurs. If it does then you set the equivalent letter in the cUnderscores array to the letter it's supposed to be. You can use a loop to do that for all the letters in the arrays. If the character wasn't found then it was a bad guess and you need to do something like decrement the number of lives they have left.

    Using the parallel arrays is quite a good idea, it's not hard to use that to do all your game logic.
    Harry.

    "From one thing, know ten thousand things."

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    Thanks Guys!
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width