|
-
April 13th, 2008, 05:19 PM
#1
[RESOLVED] Need help with a game c++ program.
The problem was resolved, thanks.
Last edited by WDSnav; April 14th, 2008 at 05:02 AM.
-
April 13th, 2008, 06:22 PM
#2
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.
-
April 13th, 2008, 07:27 PM
#3
Re: Need help with a game c++ program.
 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.
-
April 13th, 2008, 07:43 PM
#4
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."
-
April 13th, 2008, 07:49 PM
#5
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.
-
April 13th, 2008, 08:31 PM
#6
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.
-
April 14th, 2008, 09:51 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|