Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having C++ compiler issues. It's telling me that getline is undefined. This is the second part of a 2 part assignment. I had to rewrite

Having C++ compiler issues. It's telling me that getline is undefined. This is the second part of a 2 part assignment. I had to rewrite a lot of the code from last week and adding the code in from this week I can't seem to place what I have to do.

/* * Hangman Game * * Name: * Date: February 26, 2021 */ #include #include

using namespace std; //Prime functions string getWord(int); int getGameNum(); int getGuess(); void drawHangman(int level); //Main function int main() { //Declare variables int count = 0; int GameNum = getGameNum(); string word = getWord(GameNum);

for (count; count <= 6; count++) drawHangman(count);

return 0; } //This function draws a hangman based on the input misses void drawHangman(int level) { switch (level) { case 0: cout << " L----+----" << endl << " |" << endl << " |" << endl << " |" << endl << " X" << endl; break; case 1: cout << " L----+----" << endl << " | o" << endl << " |" << endl << " |" << endl << " X" << endl;

break; case 2: cout << " L----+----" << endl << " | o" << endl << "| |" << endl << " |" << endl << " X" << endl;

break; case 3: cout << " L----+----" << endl << " | o" << endl << " | /|" << endl << " |" << endl << " X" << endl; break; case 4: cout << " L----+----" << endl << " | o" << endl << " | /|\\" << endl << " |" << endl << " X" << endl; break; case 5: cout << " L----+----" << endl << " | o" << endl << " | /|\\" << endl << " | /" << endl << " X" << endl;

break; case 6: cout << " L----+----" << endl << " | o" << endl << " | /|\\" << endl << " | / \\" << endl << " X" << endl; cout << "You lost" << endl; break; default: cout << "You lost" << endl; } }

//reads the word from a file //Note: the word.txt file should be present in the same directory as the code. string getWord(int line) { string word; ifstream myfile; myfile.open("word.txt"); if (myfile.is_open()) { int lineNum; for (lineNum = 1; !myfile.eof() && getline(myfile, word); lineNum++) { if (lineNum == line) break; }

if (lineNum < line) { cout << "Invalid user input."; }

myfile.close(); }

else { cout << "Couldn't open word.txt" << endl; }

return word; }

//This function prompts the user for an input int getGameNum() { int GameNum; cout << "Game? "; cin >> GameNum; return GameNum; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions