Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Ashley Jerome
- Project 1
- Part 4
- Interactive Hangman application that displays a gradually hanging man.
- 10/25/10
- */
- #include <stdio.h>
- /*needed for strcpy in randWord function for assigning
- strings to arrays*/
- #include <string.h>
- /*function prototype definitions*/
- void randWord(int);
- void checkGuess(char);
- void enterGuess();
- int i;
- //Correct number of guesses
- int correct = 0;
- //word to be guessed
- char guessed[7]={'*','*','*','*','*','*','*'};
- //stored word
- char word[7];
- //current guess
- char guess;
- //already guessed letter
- char guesses[25];
- int main()
- {
- randWord(i);
- printf("Welcome to Hangman!\n");
- //Edit
- while(correct != 7)
- {
- enterGuess();
- }
- printf("\nYou win!\n");
- }
- /*creates a random number and assigns it to a word which is stored in an array*/
- void randWord(int i)
- {
- srand(time(NULL));
- int max=9;
- int min=0;
- int correct;
- //determine a random number for a word for Hangman
- correct=random()%((max+1)-min)+min;
- switch(correct)
- {
- case 0: {strcpy(word, "postfix");
- break;}
- case 1: {strcpy(word, "integer");
- break;}
- case 2: {strcpy(word, "process");
- break;}
- case 3: {strcpy(word, "comment");
- break;}
- case 4: {strcpy(word, "program");
- break;}
- case 5: {strcpy(word, "command");
- break;}
- case 6: {strcpy(word, "compute");
- break;}
- case 7: {strcpy(word, "logical");
- break;}
- case 8: {strcpy(word, "compile");
- break;}
- case 9: {strcpy(word, "pointer");
- break;}
- }
- }
- /*void isGuessed(char a)
- {
- int i;
- for(int i=0; i<25; i++)
- {
- if(a==guesses[i])
- {
- printf("You already guessed %c. Enter another letter.\n");
- }else
- }
- }*/
- void checkGuess(char a)
- {
- int i;
- int j;
- for (i=0; i<7; i++)
- {
- if(a==word[i])
- {
- guessed[i]=a;
- //Edit
- correct = correct + 1;
- }
- }
- //Output
- for (j=0; j<7; j++)
- {
- printf("%c", guessed[j]);
- }
- }
- //Edit
- void enterGuess()
- {
- printf("\nEnter your guess.\n");
- scanf("%c", &guess);
- checkGuess(guess);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement