Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I wish to preface this with the fact that I am still new to the C++ scene. With that being said, I am working

Hello,

I wish to preface this with the fact that I am still new to the C++ scene. With that being said, I am working with a framework for an assignment where I have to fill in the blanks. I have taken the liberty of modifying the code for more modern consoles, but I can't seem to get it working quite right, as the program is still recognizing the previous input in the selection screen as well as printing the previous input selections to program output. The program also uses multiple .cpp and .h files.

The only thing that I can see is wrong is I get the following error code: C26812: The enum type 'PlayerOptions' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). This error code is in this line of code in the GameLoop.cpp file: PlayerOptions chosenOption = PlayerOptions::None; I have attempted to change enum PlayerOptions to enum class PlayerOptions in GameLoop.cpp to no success.

Ideally, the program would be asking the user to select an option of 1-7 of which video game console that they wish to play while looping through the menu ad infinitum until the user chooses to quit; however, the framework I was supplied with only contained 1-6 (None doesn't count as it causes the program to throw an exception to the user). This initial 1-6 is what is being displayed in my user menu (Quit, PS4, XBOX, Wii, PC) and subsequently, the only options that the user can select. I'm trying to make it so that the user can select from more modern and future consoles, so the menu I want the program to display includes: (Quit, PlayStation 4, PlayStation 5, Xbox One, Xbox Series X, Nintendo Switch, PC).

A small update on progress: I came back to the code after a break and it is now functioning somewhat as expected, however, it is now missing one option: Option 1: Quit. I am still seeing the C26812 error in this line of code: PlayerOptions chosenOption = PlayerOptions::None;.

//Text Adventure.cpp

#include #include "Gameloop.h" #include "Player.h" #include "PlayerOptions.h" using namespace std;

int main() { //Created an object for game. Game game; //Calling the method RunGame on the object game. game.RunGame();

system("pause"); return 0; } -----------------------------------------------------------

//PlayerOptions.h #pragma once enum PlayerOptions { //Expanding on options for the user with modern and future consoles. Quit, PlayStation4, PlayStation5, XBoxOne, XBoxSeriesX, NintendoSwitch, PC, None }; ----------------------------------------------------------------------------------------------

//Gameloop.h

#pragma once #include "Player.h" #include "PlayerOptions.h" class Game { private: Player m_player; void WelcomePlayer(); void GivePlayerOptions() const; void GetPlayerInput(std::string& playerInput) const; PlayerOptions EvaluateInput(std::string& playerInput) const; public: void RunGame(); };

---------------------------------------------------------------------------------------------------

//Player.h

#pragma once #include class Player { private: std::string m_name; public: Player() { }

void SetName(const std::string& name) { m_name = name; }

const std::string& GetName() const { return m_name; } };

--------------------------------------------------------------------------- //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 play? (Enter a corresponding number)" << endl << endl; cout << "1: " << endl << endl; cout << "2: PlayStation 4" << endl; cout << "3: PlayStation 5" << endl; cout << "4: XBox One" << endl; cout << "5: XBox Series X" << endl; cout << "6: Nintendo Switch" << endl; cout << "7: PC" << endl; cout << "8: None" << endl; } void Game::GetPlayerInput(string& playerInput) const { cin >> playerInput; } PlayerOptions Game::EvaluateInput(string& playerInput) const { //Expanding on the playerInput reader to allow for more options. PlayerOptions chosenOption = PlayerOptions::None; if (playerInput.compare("1") == 0) { cout << "Understood, quitting the program..." << endl << endl; chosenOption = PlayerOptions::Quit; } else if (playerInput.compare("2") == 0) { cout << "You have chosen to play the PlayStation 4." << endl << endl; } else if (playerInput.compare("3") == 0) { cout << "You have chosen to play the Playstation 5." << endl << endl; } else if (playerInput.compare("4") == 0) { cout << "You have chosen to play the Xbox One." << endl << endl; } else if (playerInput.compare("5") == 0) { cout << "You have chosen to play the Xbox Series X." << endl << endl; } else if (playerInput.compare("6") == 0) { cout << "You have chosen to play the Nintendo Switch." << endl << endl; } else if (playerInput.compare("7") == 0) { cout << "You have selected to play the PC." << endl << endl; } else { cout << "I don't recognize your selection. Please try again." << endl << endl; } return chosenOption; } void Game::RunGame() { WelcomePlayer(); bool shouldEnd = false; while (shouldEnd == false) { GivePlayerOptions(); string playerInput; GetPlayerInput(playerInput); shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit; } } The only thing that I can see is wrong is I get the following error code: C26812: The enum type 'PlayerOptions' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). This error code is in the file GameLoop.cpp on Line 32 if it helps. I have attempted to change enum PlayerOptions to enum class PlayerOptions to no success.

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

More Books

Students also viewed these Databases questions