Help c++
Description:
moon racecar program cat word
Sample Run #1 (bold, underlined text is what the user types):
Game? 3 L----+---- | | | X L----+---- | O | | X L----+---- | O | | | X L----+---- | O | /| | X L----+---- | O | /|\ | X L----+---- | O | /|\ | / X L----+---- | O | /|\ | / \ X You lost Answer: program
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
vector< string> solution;
string word;
int fault = 0;
int hints = 0;
void checkWinner(bool result);
void findLetters(char letter,string word)
{
vector< int > arr;
const char chCharToSearch = letter; //letter to find
size_t nCharacterOffset = word.find (chCharToSearch, 0); //first instance of letter
if(nCharacterOffset != string::npos){
arr.push_back(nCharacterOffset);
}
while (nCharacterOffset != string::npos)
{
size_t nCharSearchOffset = nCharacterOffset + 1;
nCharacterOffset = word.find(chCharToSearch,nCharSearchOffset);
if(nCharacterOffset != string::npos){
arr.push_back(nCharacterOffset);
}
}
if(arr.size() != 0){
for (int i = 0; i < arr.size(); i++){
int k = arr[i];
solution[k] = word.at(k);
hints++;
if(i == arr.size() - 1){
checkWinner(true);
}
}
} else {
checkWinner(false);
}
}
void getsolution(){
char letter;
cout <<"\n Type a letter: " << endl;
cin >> letter;
findLetters(letter,word);
}
void printsolution(){
for (int j = 0; j < solution.size(); j++)
if(solution[j] == "null"){
cout << "_ ";
} else {
cout << solution[j]+" ";
}
getsolution();
}
void checkWinner(bool answer){
if(answer == 1) {
if(hints == word.length()){
cout << word << endl;
cout << "CONGRATS!!!! YOU WON THE GAME!!!!" << endl;
} else {
printsolution();
}
}
else{
fault++;
if(fault == 7){
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| /|\ \n";
cout << "| / \ \n";
cout << "| \n";
cout << "GAME OVER!! "<< endl;
}
else {
switch(fault) {
case 1 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
printsolution();
break;
case 2 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
printsolution();
break;
case 3 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| / \n";
cout << "| \n";
cout << "| \n";
printsolution();
break;
case 4 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| /| \n";
cout << "| \n";
cout << "| \n";
printsolution();
break;
case 5 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| /|\ \n";
cout << "| \n";
cout << "| \n";
printsolution();
break;
case 6 :
cout << " _________ \n";
cout << "| | \n";
cout << "| 0 \n";
cout << "| | \n";
cout << "| /|\ \n";
cout << "| / \n";
cout << "| \n";
printsolution();
break;
}
}
}
}
int main()
{
srand (time(NULL));
string words[10] = {"penguin","elephant","mexico","walnut","office","juxtaposition","aquamarine","madagascar","ferocious","cupcake","london","abc","donut","dog","cat","apple"};
int length = sizeof(words)/sizeof(words[0]);
int enteredword = rand() %length;
word = words[enteredword];
cout << "Welcome to HANGMAN!!! \nGet ready to play \n. BEST of luck!" << endl;
cout << " _________ \n";
cout << "| | \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
cout << "| \n";
//Print Dashes
for (int i = 0; i < words[enteredword].length(); i++)
{
solution.push_back("null");
if(i == words[enteredword].length()-1) {
printsolution();
}
}
}
PLEASE GIVE A THUMBS UP!!!!!!!!!!!!!!
Help c++ Description: This program is part 1 of a larger program. Eventually, it will be...
Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...
This program is part 1 of a larger program. Eventually, it will be a complete Flashcard game. For this part, the program will Prompt the user for a file that contains the questions – use getline(cin, fname) instead of cin >> fname to read the file name from the user. This will keep you in sync with the user’s input for later in the program The first line is the number of questions (just throw this line away this week)...
TEXT FILE IS ALREADY GIVEN, JUST NEED TO READ IN THE PROGRAM. Learning objectives: The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming. This project HANG MAN will focus on file I/O and string manipulation in the implementation of the game Hangman. Program Description: In this project, you will write a C++ program that simulates playing the game Hangman. This version of the game will...
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...
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 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...
C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...
This program will make Maze game. Please Help in c++ Prompt the user for a file that contains the maze. Read it into a two-dimensional array Remember you can use inputStream.get(c) to read the next character from the inputStream. This will read whitespace and non-whitespace characters Don’t forget to read the newline character at the end of each line Print the maze to the screen from your array You should include a ‘*’ in your maze to indicate where the...
javafx assisantance confused on where to start Problem Description: (Game: hangman) Write a JavaFX program that lets a user play the hangman game. The user guesses a word by entering one letter at a time, as shown in Figure followings. If the user misses seven times, a hanging man swings, as shown in Figures. Once a word is finished, the user can press the Enter key to continue to guess another word. Guess a word: ***** God Missed letters Guess...
I need help doing all these questions (1-6) ASAP. Keep in mind we are only on chapter 5 of "Building Java Programs" so too advanced code cannot be used. Please use the appropriate code coved in the chapter and the chapters before. Thank you.? Preview File Edit View Go Tools Window Help O 2.15 GB 00% Sun Nov 27 4:01:43 PM Q e E Ch.5 Problem Set.pdf e 2 of 2) a Search Ch.5 Problem Set.pdf l. te an interactive...