CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2008
    Posts
    3

    [RESOLVED] Need help with a game c++ program.

    The problem was resolved, thanks.
    Last edited by WDSnav; April 14th, 2008 at 05:02 AM.

  2. #2
    Join Date
    Apr 2008
    Posts
    15

    Re: Need help with a game c++ program.

    One thing I noticed is that you set your count equal to 1 and then increment it. So you run through a loop once(count=1), twice(count=2), thrice(count=3), and four(count=4) and then exits on the fifth time around because 5 is not less than 5. Instead make count = 0.

    Second, it's not iostream.h it's just iostream or stdlib.h it's just stdlib, and you need the header file cctype to use the toupper function.

    I hope this helps you.

  3. #3
    Join Date
    Apr 2008
    Posts
    3

    Re: Need help with a game c++ program.

    Quote Originally Posted by ThatDinkumThinkum
    One thing I noticed is that you set your count equal to 1 and then increment it. So you run through a loop once(count=1), twice(count=2), thrice(count=3), and four(count=4) and then exits on the fifth time around because 5 is not less than 5. Instead make count = 0.

    Second, it's not iostream.h it's just iostream or stdlib.h it's just stdlib, and you need the header file cctype to use the toupper function.

    I hope this helps you.
    ok when I did that, it displays an e where the first hiphen should be when running the program after player one enters the current word. I thought of this solution before but I don't know why the e is there in the first hiphen when doing that. Also dev c++ added the .h to the end of the header files.

  4. #4
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Re: Need help with a game c++ program.

    Just a couple things

    1. Arrays are 0 indexed. So you access the elements of a 5 element array
    char foo[5] as
    foo[0]
    foo[1]
    foo[2]
    foo[3]
    foo[4]

    and your count variable should start a 0

    2. when doing a check like

    if(foundAletter == true)

    always put the variable second

    if(true == foundAletter)

    this would have avoided the bug in your code

    if(foundAletter = true)

    there are other things here, but that should be enough to get it working
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  5. #5
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Need help with a game c++ program.

    Hello WDSnav,

    I love hangman!

    1. <iostream.h>, <stdlib.h> are old headers, use <iostream> and <cstblib>.

    2. If you recall, array of character strings are null terminated. so when you specify the size, say ch[5], this stores up to 4 individual letters, and one is reserved for the null. so if anything, you need to increase the size of the array, not decrease.

    Code:
    cin>>origWord[1]>>origWord[2]>>origWord[3]>>origWord[4]>>origWord[5];
    index of the array starts from zero, thus what you have up there will skip the first letter and won't print the last letter. this is one of the reason why it displys only 4 hyphens.

    4. The variable 'count' which is set to 1, and stops at 5, it loops 4 times so you need to change this also.

    I tried your game, and I liked it. (brings me back the old school days!)

    hope this helps
    Last edited by potatoCode; April 13th, 2008 at 07:53 PM.

  6. #6
    Join Date
    Apr 2008
    Posts
    3

    Re: Need help with a game c++ program.

    Thanks guys! I followed your tips and the program works now .
    Last edited by WDSnav; April 13th, 2008 at 08:34 PM.

  7. #7
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: [RESOLVED] Need help with a game c++ program.

    Just a note... I tend to get a little bothered when posts are edited like this. Even if your problem is resolved, you should leave up the original post. You know, for posterity.
    - Alon

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

Featured