Word Guessing Game C Programming

I'm trying to create a code with these prospects:

Program that simulates a simple word-guessing game, similar to Hangman (without the pictures) or television’s Wheel of Fortune (without the money and prizes). The idea is that the program will “think” of a secret phrase, and the user will try to discover the phrase by guessing one letter at a time.
The program will use a single secret phrase that it uses each time the program runs. It can be any phrase, as long as it contains at least 15 characters, including at least one space (i.e., multiple letters).
• After each guess, the program should show the current status of the user’s guesses, using dashes to indicates unguessed letters. For example, if the secret phrase is 'magical mystery tour' and the user has already guessed the letters b, y, and t, then the program should display:
------- -y-t--y t---
Any spaces in the phrase should automatically be included (i.e., the user doesn’t have to guess them).
• Keep track of the number of guesses the user makes. (If a user re-guesses a letter previously guessed, the new guess is still counted.)
• If, after the 20th guess, the user still hasn’t completely discovered the phrase, the program should display a consolation message and end the game. The consolation message should include the secret phrase.
• If the user discovers the secret phrase by the 20th guess, display a congratulatory message, along with the number of guesses the user took.

This is what I got so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
int main ()
{
	int count = 0;
	char letter;
   char word[18]= "these lovely bones";
   char guess[20];
 
   for(int i=0; i < 20;++i )
   {
   printf ("Enter a letter to guess the word\n");
	scanf("%c", &letter);
	   int flag = 0;
	   if(count == 20)
	   {
		   printf("you guessed the word\n");

	   }
	   for(int j=0; j < 20;++j)
	   {
	   if(letter == word[j])
	   {
		   printf("Letter found\n");
		   count++;
		   flag=1;

	   }
	   }
	   if (flag==0) 
	   {
		   printf("Letter not found\n");
	   }
   }

  return 0;
}


It's basically nothing but I find this code so hard. Help on any of the bullet points would be greatly appreciated.
Last edited on
char phrase[18 + 1] = "these lovely bones"; //[18+1] don't forget the NULL terminator

I tried to keep your code that would work below and give you some ideas of what you could do in the comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
int main ()
{
    int count
    char letter;
    char phrase[18 + 1] = "these lovely bones"; //[18+1] don't forget the NULL terminator
    char cur_guess[18 + 1] = "---- ------ -----"; //[18+1] don't forget the NULL terminator
    bool guessed = FALSE; //initially they haven't guessed the word
     
    for(int i=0; i < 20; ++i) //Goes from 0 - 19, gives the user 20 chances to guess.
    {
         //if the user hasn't already guessed the corrected phrase 
        {
            //get the guess from the user
            //use a function to check if the letter is in the phrase, update the current guess and print it out

            //if the letter is in the phrase then...
                //...use a function to see if the current guess matches the phrase, if so update count and guessed
        }
    }
    
    //check to see if they GUESSED the word correctly
        //print out congratulatory message and count
    //if they have NOT GUESSED the word correctly
        //print out consolation message and the phrase

    return 0;
}
Last edited on
Topic archived. No new replies allowed.