Question

Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

Word Guessing Game Assignment Help Needed.

This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start?

Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend the use of vectors for this assignment. Win condition: If the user correctly guesses and reveals all of the letters, the guessing will end and print "You win" and reveal the word. Loss condition: The user will only see a "game over" print and be revealed the word. Required functionality:

Main() Should contain the following variables: two vectors chars. One array named answer to hold a word for the user to guess. the second an exact same sized char vector initialized all to the "*" character an int named guesses initialized to double the size of your size variable. an int named revealed initialized to zero. a char named guess initialized to '0'. This should contain the base functionality of the game. A loop should control the game and check if guesses are greater than zero and revealed is less than size. Don't forget to use the vector.size() function to get the vector's size. Ask the user for a guess and call check guess. if check guess returns true, let the user know they revealed a letter and call revealLetter(). decrement guesses by one as now a turn has been consumed. Do this outside of any conditional logic above^ perform a check to see if revealed == size to see if the user revealed all the letters.

display() - This function is called anytime the contents of the vector needs to be printed on the screen.

checkGuess() - This function will return if a match is found in the answer vector passed into it. You will need to pass the user's guess to compare, the correct answer vector. This function might not make sense to you at first, but try to use this as a utility function. If it's still confusing, try doing reveal letter first and see if this still feels necessary. This might also be a good function to check for the user guessing a letter that's already been revealed. Just a thought!

revealLetter() - This void function should be passed the matching guess char, the answer vector, the word vector, and REFERENCE to "revealed" so it can be iterated. This function should look through the answer vector and find the matching element between the user's guess and the answer vector. Copy the answer element data into the word array at that exact position to simulate revealing the letter. Lastly, increment revealed.

This is all I have so far,

int main ()

{

const int size = 1;
   char answer[] = "tester";
   char ansdot[] = "******";
   int guesses = size*2;
   char guess = 0;

   return 0;

}

Once again, I need some help to start this project. That is all, Thank you.

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

// C++ program to create and implement Word Guessing game

#include <iostream>

#include <vector>

using namespace std;

// function declaration

void display(vector<char> userGuess);

bool checkGuess(char guess, vector<char> answer);

void revealLetter(char guess, vector<char> answer, vector<char> &userAnswer, int &revealed);

int main() {

               int size = 6;

               char answer[] = "tester";

               vector<char> word(size) ;

               vector<char> userAnswer(size);

               for(size_t i=0;i < userAnswer.size();i++)

               {

                              word[i] = answer[i];

                              userAnswer[i] = '*';

               }

               int guesses = 2*size;

               int revealed = 0;

               char guess = '0';

               // loop that continues till all guesses are exhausted or the word is guessed

               while(guesses > 0 && revealed < size)

               {

                              cout<<"Word : ";

                              display(userAnswer);

                              cout<<"Guess a letter : ";

                              cin>>guess;

                              if(checkGuess(guess,word))

                              {

                                             revealLetter(guess,word,userAnswer,revealed);

                              }

                              --guesses;

               }

               if(revealed == size)

                              cout<<"You win. The word was : ";

               else

                              cout<<"Game over. The word was : ";

               display(word);

               return 0;

}

// function to display a vector

void display(vector<char> inVec)

{

               for(size_t i =0;i<inVec.size();i++)

                              cout<<inVec[i];

               cout<<endl;

}

// function to check if a letter is present in the word to be guessed

bool checkGuess(char guess, vector<char> answer)

{

               for(size_t i=0;i<answer.size();i++)

                              if(answer[i] == guess)

                                             return true;

               return false;

}

// function to update user guess

void revealLetter(char guess, vector<char> answer, vector<char> &userAnswer, int &revealed)

{

               for(size_t i=0;i<answer.size();i++)

               {

                              if(answer[i] == guess)

                              {

                                             userAnswer[i] = guess;

                                             revealed++;

                              }

               }

}

//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...
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
  • 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...

  • PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In t...

    c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...

  • Create a script that presents a word-guessing game. Allow users to guess the word one letter at a...

    Create a script that presents a word-guessing game. Allow users to guess the word one letter at a time by entering a character in a form. Start by assigning a secret word to a variable. After each guess, print the word using asterisks for each remaining letter, but fill in the letters that the user guessed correctly. Store the user’s guess in a form field. For example, if the word you want users to guess is “suspicious” and the user...

  • JAVA Develop a letter guessing game in this assignment using Java. Requirements: 1). When the game...

    JAVA Develop a letter guessing game in this assignment using Java. Requirements: 1). When the game is started, generate a random letter between A and Z; 2). Display a message "I have a secret letter (A to Z), can you guess what it is?"; 3). Read the user's answer; 4). Compare the user's answer and the random secret letter generated; 5). If the user answer is before the random secret letter in the alphabet, display "Incorrect. Try something bigger" and...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

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

  • Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite...

    Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite tries to guess the word (like Hangman without the hangman, or like Wheel of Fortune without the wheel and fortune). Create two global arrays: one to hold the letters of the word (e.g. 'F', 'O', 'X'), and one to hold the current guessed letters (e.g. it would start with '_', '_', '_' and end with 'F', 'O', 'X'). Write a function called guessLetter that...

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

  • I am trying to make a word guessing game on java, where there are four letters...

    I am trying to make a word guessing game on java, where there are four letters and you have 10 guesses to try and guess the letter combination. When I try to play, it says every combination of letters I enter is correct. For example: "You have 10 guesses left. Enter your guess: wxyz There are 4 correct letter placements. Congrats!" I emailed my professor and she said one of my methods is wrong because I'm only checking for specific...

  • c++. I'm working on a hangman game. It has to utilize a class. It should show...

    c++. I'm working on a hangman game. It has to utilize a class. It should show the number of attempts that have been made, the length of the word represented by dots, and then the alphabet. There also needs to be input validation. If the word was horse, the very first attempt at the user guessing should display " 1 ..... choose: abcdefghijklmnopqrstuvwxyz ". As the user guesses letters, the number of attempts should go up, the letter should be...

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