Question
Please help with this Intro to programming in C assignment!

Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of the guessed letters (letters) o one for the users word guess (guess) Declare additional variables as needed At the beginning of each game: * o word to be guessed array- start with an empty string. Read a word from the file and store it in the word to be guessed array word in progress array should be adjusted to the correct length (that is the same size as the word read from the file but consists only of (asterisks) in the beginning (starword) guessed letters array should be empty - a character is added with each guess o o An integer will keep track of how many characters are in the array . HOW TO PLAY THE GAME . Allow the user to guess letters one character at a time. e At every stage of the game, the user should be able to view the current state of the word in progress If any letter is correctly guessed the player is notified and the letter appears in its proper location in the word (starword) and the list of guessed letters (letters) in progress array (starword), this array is displayed again with the letter(s) in place and the user can input a word . If a letter is not correct, the number of used guesses is increased. . In ALL cases, the guessed letter should be added to the array of guessed letters The user is allowed up to 6 incorrect guesses. The game is over when the word is guessed correctly or the six incorrect guesses are used up. If the player guesses the word correctly, the player is notified that they have won and the correct word is displayed. displayed again. (The player will play again with the next word in the file) If the player does not get the correct word, the player is notified that they have lost and the correct word is . When the game is over, the user should be allowed to play again without having to execute the program . Remember that the C language is case sensitive. For this program a- A. In order to do this, you will need to convert all input letters to upper or lowercase either before or during the letter matching process. You will need to have a preprocessor directive to include the library file ctype h in order to access these functions. . Be sure to add the hangmanWords.txt file to your project
media%2F164%2F1642c0f8-7e4b-4d0f-b8bc-b8
media%2Fe5b%2Fe5b05862-c227-4f3f-b0cd-d9
media%2F728%2F7281d11b-938a-4d0d-8d78-16
media%2Fd0d%2Fd0d2a988-d877-4d71-8a00-98
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source code:-
- -----------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_GUESSES 6
int main()
{
   char guess,choice;
   char visible_WordString[100];
   char WordString[255]=" ";
   char hint[255]=" ";
   int num_letters= 0,i=0,count=0,tries=0,num_vis_chars=0;
   int correct_guesses=0,correct_flag=0,repeat_flag=0;
   char incorrect_letters[255]=" ";
   do
   {
           memset(WordString,0,sizeof(WordString));
           memset(hint,0,sizeof(hint));
           printf("\nGuess the WordString: ");
           gets(WordString);
           printf("\nGive hint:");
           gets(hint);
           num_letters = strlen(WordString );
           /* displays correct guesses */
           for(i=0;i<num_letters;i++ )
           {
               visible_WordString[i]='-';
           }
           visible_WordString[num_letters] = '\0';
        printf("\nWelocme to the HANGMAN" );
           printf("\nHINT: %s", hint);
           while( tries<MAX_GUESSES)
           {
              printf("\nWordString: %s\n", visible_WordString );
              printf("\nIncorrect Guesses: %s\n", incorrect_letters );
              printf("\nGuess a letter ");
              scanf("%c", &guess );
              for(count= 0; count < num_letters; count++ )
              if(guess == visible_WordString[count] || guess == incorrect_letters[count] )
               {
                repeat_flag = 1;
                correct_flag = 1;
                break;
              }
              if( repeat_flag == 0 )
             for( count = 0; count < num_letters; count++ )
            {
                if( guess == WordString[count] )
                {   
                       visible_WordString[count] = guess;
                       correct_guesses++;
                       if( correct_guesses == num_letters )
                       {
                          printf("\nCONGRATULATIONS! You guessed the Word!" );
                          printf("\nWord: %s\n", visible_WordString );
                          exit( 0 );
                       }
                       correct_flag = 1;
                }
             }
               if( correct_flag == 0 )
               {   
                 incorrect_letters[tries] = guess;
                 tries++;
               }
               repeat_flag = 0;
               correct_flag = 0;
               printf("\nWelocme to the HANGMAN");
               printf("\nHINT: %s", hint );
           }
           printf("\nYou did not guess the word." );
           printf("\nWORD: %s\n", visible_WordString );
           printf("\nWant to play Again press y for yes 'n' for No");
           choice=getchar();
   }while(choice=='y'||choice=='Y');
   return 0;
}

Sample Output:-
--------------------------------

Guess the WordString: hangman

Give hint:h

Welocme to the HANGMAN
HINT: h
WordString: -------

Incorrect Guesses:

Guess a letter g

Welocme to the HANGMAN
HINT: h
WordString: ---g---

Incorrect Guesses:

Guess a letter
Welocme to the HANGMAN
HINT: h
WordString: ---g---

Incorrect Guesses:


Guess a letter m

Welocme to the HANGMAN
HINT: h
WordString: ---gm--

Incorrect Guesses:


Guess a letter
Welocme to the HANGMAN
HINT: h
WordString: ---gm--

Incorrect Guesses:


Guess a letter a

Welocme to the HANGMAN
HINT: h
WordString: -a-gma-

Incorrect Guesses:


Guess a letter
Welocme to the HANGMAN
HINT: h
WordString: -a-gma-

Incorrect Guesses:


Guess a letter n

Welocme to the HANGMAN
HINT: h
WordString: -angman

Incorrect Guesses:


Guess a letter
Welocme to the HANGMAN
HINT: h
WordString: -angman

Incorrect Guesses:


Guess a letter h

CONGRATULATIONS! You guessed the Word!
Word: hangman

--------------------------------
Process exited after 23.48 seconds with return value 0
Press any key to continue . . .


Guess a letter h Welocme to the HANGMAN HINT: m WordString: h-ng--n Incorrect Guesses: Guess a letter Welocme to the HANGMAN

Add a comment
Know the answer?
Add Answer to:
Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is for C programming: You will be given files in the following format: n word1...

    This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • C++ Hangman (game) In this project, you are required to implement a program that can play...

    C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...

  • C++ programming Submit assignment to Blackboard by the midnight on the due date listed above. (Verify...

    C++ programming Submit assignment to Blackboard by the midnight on the due date listed above. (Verify if your submission is completed.) The only people you are to discuss this project with are myself and the CS Department tutor. Duplicate code, if discovered, will result in a 0 grade. Your source file(s) should follow the Computer Science Coding Standards (available at the Computer Science Homepage) including proper indenting and spacing 1 Overview program, you will play a game of hangman. In...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • Create the game hangman using c code: Program description In the game of hangman, one player...

    Create the game hangman using c code: Program description In the game of hangman, one player picks a word, and the other player has to try to guess what the word is by selecting one letter at a time. If they select a correct letter, all occurrences of the letter are shown. If no letter shows up, they use up one of their turns. The player is allowed to use no more than 10 incorrect turns to guess what the...

  • JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The...

    JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT