Question

Note wordBank, an array of 10 strings (char *s). Your program should do the following: Select a word at random from the wordB

Current word: 亥c c* 8 remain. . .Enter a letter to guess: Current word: Sc**c 8 remain. . .Enter a letter to guess 91 Current

Note wordBank, an array of 10 strings (char *s). Your program should do the

following:

1. Select a word at random from the wordBank. This is done for you.

2. On each turn display the word, with letters not yet guessed showing as *'s,

and letters that have been guessed showing in their correct location

3. The user should have 10 attempts (?lives?). Each unsuccessful guess costs

one attempt. Successful guesses do NOT count as a turn.

4. You must use the C-String library (#include <cstring>) functions strlen() and

strcmp() in your program [strcmp() can compare when the guessed word

matches the target/selected word fro? the wordBa?k… meaning the user

won/finished]

5. You must complete and use the function

int processGuess(char* word, const char* targetWord, char guess)

This function should take the pointer to the current value of the word

guessed thus far, the pointer to the target/selected word from the

wordBank, and the character that the user guessed. It should change any *'s

to actual good characters for the letter the user guessed and return a count

of how many times the guessed letter appears in that word. In this way, if

you return 0, it means the user guessed a letter that did NOT appear and

thus should lose a turn back in your main().

6. At every turn display the current version of the guessed word and how many

turns remain

7. At the end of the game give a descriptive message whether the user won or

lost

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;

// Function declarations
void display(char word[], int len);
int processGuess(char *word,char *targetWord,char guess);
int main()
{

// Declaring variables
srand(time(NULL));   
char guess = 0;

char WORDBANK[][8] = { "program", "puzzles", "sqeeze", "circuit", "devoted", "journey", "version",
"totally", "respect" };
int i, num;
num = (rand() % 9);

char *targetWord=WORDBANK[num];

int len=strlen(targetWord);
int size=len;

int guesses = 10;
char word[len];
  
// Initializin the answer array with *
for (int i = 0; i < len; i++)
{
word[i] = '*';
}

  
cout << "Guess the word!" << endl;
  
  
  
  
/* This loop contiues to execute until
* the no of guesses is greater than zero
* and revealed is less than size
*/
while (guesses > 0 && size!=0)
{
   cout<<" Current Word: ";
display(word,len);

   cout<<guesses<<" remain...Enter a letter to guess :"<<endl;
   cin>>guess;
  
   int cnt=processGuess(word,targetWord,guess);
  
  
  
// calling the function
if (cnt!=0)
{
   size-=cnt;
  
}
else
{
guesses--;
}
  
  
  
}
if (size==0)
{
   cout<<"The Word was :";
display(targetWord, len);
cout << "You Win!" << endl;
}
else if(guesses==0)
{
       cout<<"The Word was :";
display(targetWord, len);
cout<<"You Lost!"<<endl;
   }

return 0;
}
// This function will print the word
void display(char word[], int size)
{
int i;
for (i = 0; i < size; i++)
{
cout << word[i];
}
cout << endl;
}
/* This function will check whether the user guessed
* char is available in word char or not
*/
int processGuess(char *word,char *targetWord,char guess)
{
   int cnt=0;
   for(int i=0;i<strlen(targetWord);i++)
   {
       if(guess==targetWord[i] && word[i]=='*')
       {
       word[i]=targetWord[i];
       cnt++;  
       }
      
   }
   return cnt;
}

_______________________________

Output#1:

ǐ. C:Program Files (x86)Dev-CppMinGVV64binGuessingword.exe Guess the word Current WordRx* 10 remain. ..Enter a letter to

_________________

Output#2:

CAProgram Files (x86)\Dev-CpplMinGW641bin GuessingWord.exe Guess the word Current Word: 10 remain. . .Enter a letter to guess

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Note wordBank, an array of 10 strings (char *s). Your program should do the following: 1....
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
  • 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 help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    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...

  • 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...

  • 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...

  • 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...

  • 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...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • Your Python program should perform the following three tasks: 1. After getting a word of input...

    Your Python program should perform the following three tasks: 1. After getting a word of input from the user (i.e., any string), your program should use a while (or for) loop to print out each of the letters of the word. Just remember that strings in Python start with element 0! 2. Your program should then use another loop to print out each of the letters of the (same) word in reverse order! 3. Ask the user for a letter...

  • 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...

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