|
-
Mar 2nd, 2001, 05:52 PM
#1
Thread Starter
Hyperactive Member
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
-
Mar 2nd, 2001, 06:25 PM
#2
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?
-
Mar 2nd, 2001, 06:28 PM
#3
Thread Starter
Hyperactive Member
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
-
Mar 2nd, 2001, 06:41 PM
#4
Code:
char cWord[5]; // 6 elements including 0
char cUnderscores[5];
cWord = "Myword";
cUnderscores = "_____";
-
Mar 2nd, 2001, 07:31 PM
#5
Thread Starter
Hyperactive Member
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
-
Mar 3rd, 2001, 12:56 AM
#6
Thread Starter
Hyperactive Member
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
-
Mar 3rd, 2001, 04:03 AM
#7
Frenzied Member
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."
-
Mar 3rd, 2001, 10:59 AM
#8
Thread Starter
Hyperactive Member
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|