WDSnav
April 13th, 2008, 05:19 PM
The problem was resolved, thanks.
|
Click to See Complete Forum and Search --> : [RESOLVED] Need help with a game c++ program. WDSnav April 13th, 2008, 05:19 PM The problem was resolved, thanks. ThatDinkumThinkum April 13th, 2008, 06:22 PM 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. WDSnav April 13th, 2008, 07:27 PM 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. souldog April 13th, 2008, 07:43 PM 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 potatoCode April 13th, 2008, 07:49 PM 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. 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 WDSnav April 13th, 2008, 08:31 PM Thanks guys! I followed your tips and the program works now :). Hermit April 14th, 2008, 09:51 AM 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. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |