Write a program that will play the Lingo game. This game will randomly produce a five-letter word, displaying just the first letter and letting the player to guess the rest. The player may have only five trials. Give points accordingly.
int main ()
{
char guessedWord; //this is user guessing word
int maxAttempt = 5; //max attempt for user
int attempt;
const int totalWords = 3; //total word in the game
srand((unsigned)time(NULL)); //generate a random seed
int ran = rand()% totalWords; //Generate a random number between 0 to numberOfWords - 1
char *correctWord[] = {"ONE", "TWO", "THREE"}; //list of word in the game. is there any other way to store the word?
char *guessed [] = {"O**", "T**", "T***"}; //show only the first letter. is there any other way to print it?
printf("\n\n\t\tWelcome to Lingo Game\n\n\n"); //title
while ((strcmpi (correctWord [ran, guessedWord) != 0) && attempt < 5) //compare two string
{
printf("\n"); //for spacing
printf("%s\n\n", guessed[ran]); //print first letter of the word
printf("Guess the word: "); //ask for word
scanf ("%s", &guessedWord); //scan for the letter
attempt += 1; //increement
}
if ((strcmpi(correctWord [ran], guessedWord) == 0))//If word was guessed, congrats to the winner
printf("Congratulations! You WIN!!!!!\n");
else
printf("Sorry, you failed to guess it\n"); //too many guesses
Firstly put your code between [code][/code] tags so it can be easily read.
You're missing a ] in the while loop but that's probably a typo.
Your correctWord array is fine. After all an array of c-strings is what you need. You should make that constchar* correctWord[] though. const because you're not allowed to modify the contents of that array.
Your guessed array is not so good. Though it could work too. I don't know how this game is supposed to work. If for example the random word is "three" an I guess "third" would guessed then become "th***" ?