Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help here, when I run this program, it will print out the statement You have chosen to Quit! twice before it actually closes.

Need some help here, when I run this program, it will print out the statement "You have chosen to Quit!" twice before it actually closes. Same with "I do not recognise that option, try again!" Can someone help me out? The issue is within the GameLoop.cpp and I know it's because of the IF statement on line 75, but I can't figure out a way around using it.

GameLoop.cpp

#include "GameLoop.h" #include

using namespace std;

void Game::WelcomePlayer() { cout << "Welcome to Text Adventure!" << endl << endl; cout << "What is your name?" << endl << endl;

string name; cin >> name; m_player.SetName(name);

cout << endl << "Hello " << m_player.GetName() << endl; }

void Game::GivePlayerOptions() const { cout << "What would you like to do? (Enter a corresponding number)" << endl << endl; cout << "1: Enter my preferred game console." << endl; cout << "2: Quit" << endl << endl;

}

void Game::GetPlayerInput(string& playerInput) const { cin >> playerInput; }

PlayerOptions Game::EvaluateInput(string& playerInput) const { PlayerOptions chosenOption = PlayerOptions::None;

if (playerInput.compare("1") == 0) { chosenOption = PlayerOptions::ConsoleType; } else if (playerInput.compare("2") == 0) { cout << "You have chosen to Quit!" << endl << endl; chosenOption = PlayerOptions::Quit; } else { cout << "I do not recognise that option, try again!" << endl << endl; }

return chosenOption; }

void Game::GetConsoleType() { cout << "What is your preferred game console?" << endl; string console; cin >> console; m_player.SetConsole(console);

cout << "You have chosen the " << m_player.GetConsole() << " as your preferred console." << endl << endl;

}

void Game::RunGame() { WelcomePlayer();

bool shouldEnd = false; while (shouldEnd == false) { GivePlayerOptions(); string playerInput; GetPlayerInput(playerInput); // Created IF statement to get console type if user chooses that option. if (EvaluateInput(playerInput) == PlayerOptions::ConsoleType) { GetConsoleType(); } shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit; }

}

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions