Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program should be written in C. For this assignment, your mission is to write a program that plays the game of Hangman. The game is

Program should be written in C.

For this assignment, your mission is to write a program that plays the game of Hangman. The game is to be played between two players. The program should ask for the names of the two players and do a coin toss to determine who goes first. If its head, player 1 goes first, otherwise player 2 goes first. Whoever goes first, has to think of a word which the other player has to guess in six attempts.

The program should ask the player to enter the secret word. This will be followed by a screen clear (print a new line character 200-400 times). The other player has to guess this word.The program then prints out a row of dashesone for each letter in the secret wordand asks the user to guess a letter. If the user guesses a letter that is in the word, the word is redisplayed with all instances of that letter shown in the correct positions, along with any letters correctly guessed on previous turns. If the letter does not appear in the word, the user is charged with an incorrect guess. The user keeps guessing letters until either (1) the user has correctly guessed all the letters in the word or (2) the user has made six incorrect guesses.

Afterwards the roles switch, and we keep a record of the wins and losses. The game continues until we have a winner. For instance, if player 1 guesses the word while player 2 is unable to guess the word, then player 1 wins. If they both guess correctly or both are unable to guess in a round, the game goes to the round 2, and continues until we have a winner. See sample run below.

Your program should exactly emulate the sample run. The users may enter uppercase or lowercase characters, but your program should not differentiate between them. As in H is equivalent to h.

Your solution should use functions. It should have at least 2 functions other than the main function.

Sample run (User input in bold and italics)

Enter player 1 name: Nazim

Enter player 2 name: Sarah

Coin toss to decide who goes first...and its a head. Nazim goes first. 

Nazim, enter your secret word: Hello #LOTS OF NEW LINE SPACES Sarah, enter a letter: a Word: _ _ _ _ _

Incorrect guesses: 1 Sarah, enter a letter: e Word: _ e _ _ _ Incorrect guesses: 1 Sarah, enter a letter: i Word: _ e _ _ _ Incorrect guesses: 2 Sarah, enter a letter: o Word: _ e _ _ o Incorrect guesses: 2 Sarah, enter a letter: h Word: h e _ _ o Incorrect guesses: 2 Sarah, enter a letter: l Word: h e l l o Incorrect guesses: 2 Sarah wins! Sarahs turn. Sarah, enter your secret word: meagre #LOTS OF NEW LINE SPACES Nazim, enter a letter: a Word: _ _ a _ _ _ Incorrect guesses: 0

Craig, enter a letter: e

Word: _ e a _ _ e

Incorrect guesses: 0

Nazim, enter a letter: i

Word: _ e a _ _ e

Incorrect guesses: 1

Nazim, enter a letter: o

Word: _ e a _ _ e

Incorrect guesses: 2

Nazim, enter a letter: h Word: _ e a _ _ e

Incorrect guesses: 3

Nazim, enter a letter: r

Word: _ e a _ r e

Incorrect guesses: 3

Nazim, enter a letter: r

Word: _ e a _ r e

Incorrect guesses: 3

Nazim, enter a letter: m

Word: m e a _ r e

Incorrect guesses: 3

Nazim, enter a letter: g

Word: m e a g r e

Incorrect guesses: 3

Nazim wins!

Score: Nazim: 1 

Sarah: 1 We have a tie, another round! Nazim, enter your secret word: bamboozle #LOTS OF NEW LINE SPACES Sarah, enter a letter: a Word: _ a _ _ _ _ _ _ _ Incorrect guesses: 0 Sarah, enter a letter: e Word: _ a _ _ _ _ _ _ e Incorrect guesses: 0 Sarah, enter a letter: i Word: _ a _ _ _ _ _ _ e Incorrect guesses: 1 Sarah, enter a letter: o Word: _ a _ _ o o _ _ e Incorrect guesses: 1 Sarah, enter a letter: r Word: _ a _ _ o o _ _ e Incorrect guesses: 2 Sarah, enter a letter: t Word: _ a _ _ o o _ _ e Incorrect guesses: 3 Sarah, enter a letter: l Word: _ a _ _ o o _ l e Incorrect guesses: 3 Sarah, enter a letter: m Word: _ a m _ o o _ l e

Incorrect guesses: 3 Sarah, enter a letter: g Word: _ a m _ o o _ l e Incorrect guesses: 4 Sarah, enter a letter: p Word: _ a m _ o o _ l e Incorrect guesses: 5 Sarah, enter a letter: f Word: _ a m _ o o _ l e Incorrect guesses: 6 Sarah loses! Sarahs turn. Sarah, enter your secret word: timely #LOTS OF NEW LINE SPACES Nazim, enter a letter: a Word: _ _ _ _ _ _ Incorrect guesses: 1 Nazim, enter a letter: e Word: _ _ _ e _ _ Incorrect guesses: 1 Nazim, enter a letter: i Word: _ i _ e _ _ Incorrect guesses: 1 Nazim, enter a letter: o Word: _ i _ e _ _ Incorrect guesses: 2 Nazim, enter a letter: t

Word: t i _ e _ _ Incorrect guesses: 2 Nazim, enter a letter: y Word: t i _ e _ y Incorrect guesses: 2 Nazim, enter a letter: l Word: t i _ e l y Incorrect guesses: 2 Nazim, enter a letter: Word: t i _ e l y Incorrect guesses: 2 Nazim, enter a letter: m Word: t i m e l y Incorrect guesses: 2 Nazim wins! Score: Nazim: 2 Sarah: 1 Nazim wins!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago