Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. /*Ashley Jerome
  2. Project 1
  3. Part 4
  4. Interactive Hangman application that displays a gradually hanging man.
  5. 10/25/10
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. /*needed for strcpy in randWord function for assigning
  11. strings to arrays*/
  12. #include <string.h>
  13.  
  14. /*function prototype definitions*/
  15. void randWord(int);
  16. void checkGuess(char);
  17. void enterGuess();
  18.  
  19.     int i;
  20.     //Correct number of guesses
  21.     int correct = 0;
  22.     //word to be guessed
  23.     char guessed[7]={'*','*','*','*','*','*','*'};
  24.     //stored word
  25.     char word[7];
  26.     //current guess
  27.     char guess;
  28.     //already guessed letter
  29.     char guesses[25];
  30.    
  31.  
  32. int main()
  33. {
  34.     randWord(i);
  35.     printf("Welcome to Hangman!\n");
  36.     //Edit
  37.     while(correct != 7)
  38.     {
  39.         enterGuess();
  40.     }
  41.     printf("\nYou win!\n");
  42. }
  43. /*creates a random number and assigns it to a word which is stored in an array*/
  44. void randWord(int i)
  45. {
  46.     srand(time(NULL));
  47.  
  48.     int max=9;
  49.     int min=0;
  50.     int correct;
  51.     //determine a random number for a word for Hangman
  52.     correct=random()%((max+1)-min)+min;
  53.  
  54.     switch(correct)
  55.     {
  56.     case 0: {strcpy(word, "postfix");
  57.         break;}
  58.     case 1: {strcpy(word, "integer");
  59.         break;}
  60.     case 2: {strcpy(word, "process");
  61.         break;}
  62.     case 3: {strcpy(word, "comment");
  63.         break;}
  64.     case 4: {strcpy(word, "program");
  65.         break;}
  66.     case 5: {strcpy(word, "command");
  67.         break;}
  68.     case 6: {strcpy(word, "compute");
  69.         break;}
  70.     case 7: {strcpy(word, "logical");
  71.         break;}
  72.     case 8: {strcpy(word, "compile");
  73.         break;}
  74.     case 9: {strcpy(word, "pointer");
  75.         break;}
  76.     }
  77. }
  78. /*void isGuessed(char a)
  79. {
  80.     int i;
  81.     for(int i=0; i<25; i++)
  82.     {
  83.         if(a==guesses[i])
  84.         {
  85.             printf("You already guessed %c. Enter another letter.\n");
  86.         }else
  87.     }
  88. }*/
  89. void checkGuess(char a)
  90. {
  91.     int i;
  92.     int j;
  93.     for (i=0; i<7; i++)
  94.     {
  95.         if(a==word[i])
  96.         {
  97.             guessed[i]=a;
  98.             //Edit
  99.             correct = correct + 1;
  100.         }
  101.     }
  102.    
  103.     //Output
  104.     for (j=0; j<7; j++)
  105.     {
  106.         printf("%c", guessed[j]);
  107.     }
  108.    
  109. }
  110.  
  111. //Edit
  112. void enterGuess()
  113. {
  114.     printf("\nEnter your guess.\n");
  115.     scanf("%c", &guess);
  116.     checkGuess(guess);
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement