Menu

[solved]-Hello Currently Problem Code Verified Exit Going Another Function Enter Y Exit Exit Enter Q39057918

Hello, i am currently having a problem with my code. My verifiedexit is going to another function when i enter y to exit. But wheni just do the exit and enter nothing else the verified exit works.I am very confused as to why because my syntax looks right. I putthe 3 files below. Any and all help is appreciated.

C++ Visual Studio 2017

SOURCE.CPP

#include “cPlayer.h”

using namespace std;

int main()
{
   cPlayer p;
   p.fMenu();
   return 0;
}

CHPLAYER.CPP

#include “cPlayer.h”
char chChoice1 = ‘ ‘;
char chChoice2 = ‘ ‘;
char chChoice3 = ‘ ‘;
cPlayer::cPlayer()
{
}
cPlayer::~cPlayer()
{
}

void cPlayer::fMenu()
{
   do
   {
       cout << “nt–Menu–“<< endl;
       cout << “1) Enter PlayerName” << endl;
       cout << “2) Select Player’sTeam” << endl;
       cout << “3) Display PlayerInfo” << endl;
       cout << “4) Exit” <<endl;
       cin >> chChoice1;
       system(“cls”);

       switch (chChoice1)
       {
       case ‘1’:
          fPlayerName();
          system(“pause”);
          system(“cls”);
           fMenu();
           break;

       case ‘2’:
          fSelectTeam();
          system(“pause”);
          system(“cls”);
           fMenu();
           break;

       case ‘3’:
          fPlayerInfo();
          system(“pause”);
          system(“cls”);
           fMenu();
           break;
          
       case ‘4’:
          fVerifyExit();

           break;

       default:
           cout <<“**********************” << endl;
           cout <<“–Not a valid option–” << endl;
           cout <<“**********************” << endl;
          system(“pause”);
           break;
          
       }
   } while (chChoice1 != ‘4’);
}

void cPlayer::fSelectTeam()
{
   //chChoice2 is a character variable

   while (true)
   {
       cout << “Please select yourteam color.” << endl;
       cout << “1) Red” <<endl;
       cout << “2) Blue” <<endl;
       cin >> chChoice2;

       switch (chChoice2)
       {
       case ‘1’:
          system(“cls”);
          sPlayer.strTeamName = “Red”;
           fMenu();
           break;

       case ‘2’:
          system(“cls”);
          sPlayer.strTeamName = “Blue”;
           fMenu();
           break;

       default:
           cout <<“Invalid Input.” << endl;
           return;
       }
   }
}

void cPlayer::fPlayerInfo()
{
   cout << “t–PLAYER INFO–” << endl;
   cout << “Player Name: ” <<sPlayer.strPlayerName << endl;
   cout << “Team: ” << sPlayer.strTeamName<< endl;
}

void cPlayer::fPlayerName()
{
   cout << “Enter the players name.” <<endl;
   cin >> sPlayer.strPlayerName;//MAKE A GETLINE
}

char cPlayer::fVerifyExit()
{
   system(“cls”);
   cout << “Do you want to exit (Y/y).” <<endl;
   cin >> chChoice3;
   switch (chChoice3)
   {
   case ‘Y’:
   case ‘y’:
       chChoice1 = ‘4’;
       break;
   default:
       chChoice1 = ‘ ‘;

       break;
   }
   return chChoice1;
}
CHPLAYER.H

#ifndef CPLAYER
#define CPLAYER

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

class cPlayer
{
public: //Interface(Setter/Getters go here aswell)
   cPlayer();
   ~cPlayer();
   void fMenu();
private: //Implementation(Does things but doesnt need to beseen)
   //functions
   void fPlayerName();//player name
   void fSelectTeam();//select team
   void fPlayerInfo();//displays palyer info
   char fVerifyExit();//verifies that the user wantsexit, if not show menu
   //variable
   bool bolPlayerInfoComplete = false;//flag to make sureit has a name a team
   //structure
   struct sPlayerTemplate
   {
       string strPlayerName = “”;
       string strTeamName = “”;
   };
   sPlayerTemplate sPlayer;

};

#endif // !CPLAYER

Expert Answer


Answer to Hello, i am currently having a problem with my code. My verified exit is going to another function when i enter y to exi… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *