![]() |
|
#1
|
|||
|
|||
Small help with this program pleaseI've been developing a simple hangman program in C for a collage course i'm doing. It complies and runs (mostly) but it has an problem that i'm scratching my head about. In the Rungame function it doesn't seem to pick up the...
CPP / C++ / C Code:
Last edited by JdS : 10-Jun-2004 at 08:12.
Reason: Please enclose c code in [c] & [/c] for syntax highlighting
|
|
#2
|
|||
|
|||
|
for starters, you need a closing brace after the if (copy[count] == Letter ) Also change the if(continue ='y' ) clause in main to while if you want to repeat it. Also there is some problem with input stream. Can't be of much help there as i'm not familiar with c function scanf.
__________________
spasms!!! |
|
#3
|
||||
|
||||
|
Quote:
This is definitely the root of your problem, because the if(Correct==0) is never reached unless the letter is correct and if the letter is correct, then correct is set to 1.... Formatting of your code can really help you identify errors like this. It appears that you may have thrown an extra '}' at the end of the function to get it to compile. It really helps me out to be extra careful on the indentation to make sure that my opening and closing brackets line up. For instance: CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Solution.Hi! I don't know if you still need it but i corrected the code so you can use it.
#include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #define MAX 20 void Rungame(char Words[][21]); int main() { char Continue = 'Y'; char Words[20][21] = {"computer", "keyboard", "mouse", "processor", "memory", "screen"}; Rungame(Words); } void Rungame(char Words[][21]) { int Word; int Size; int state; int Count; char Guess[MAX]; char Copy[MAX]; char Letter; state = 8; Count = 0; Word = rand() %3; strcpy(Copy,Words[Word]); Size = strlen(Words[Word]); for(; Count < Size; Count++) { Guess[Count] = '-'; } Guess[Count] = '\0'; while(state >= 0) { printf("Guess a letter: "); scanf(" %c", &Letter); for(Count = 0; Count < Size; Count++) { if(Copy[Count] == Letter) { Guess[Count] = Letter; printf("Good guess!\n"); pri ntf("%s\n ", Guess); } } if(times == 0) { state = state - 1; printf("Sorry, bad guess. You have %d lifes left.\n", state); } if(strcmp(Words[Word], Guess) == 0) { printf("Well Done!"); return; } } } |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with a C program (Long) | McFury | C Programming Language | 3 | 29-Apr-2004 21:06 |
| Modify a C program | ayoub | C Programming Language | 3 | 15-Mar-2004 12:34 |
| error during program | rjd72285 | C++ Forum | 0 | 11-Nov-2003 19:49 |
| one program access another? | dgoulston | C++ Forum | 1 | 07-Oct-2003 12:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The