Hello i am having a bit of trouble with a verified exit for my program. For some reason when trying to exit it loops to the team selection function?
C++ Visual Studio 2017
#include "cPlayer.h"
char chChoice1 = ' ';
char chChoice3 = ' ';
cPlayer::cPlayer()
{
}
cPlayer::~cPlayer()
{
}
void cPlayer::fMenu()
{
char chChoice3 = ' ';
do
{
cout << "\n\t--Menu--"
<< endl;
cout << "1) Enter Player
Name" << endl;
cout << "2) Select Player's
Team" << endl;
cout << "3) Display Player
Info" << 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 != 'e');
}
void cPlayer::fSelectTeam()
{
//chChoice2 is a character variable
char chChoice2 = ' ';
while (true)
{
cout << "Please select your
team 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 GET
LINE
}
char cPlayer::fVerifyExit()
{
char chChoice = ' ';
system("cls");
cout << "Do you want to exit (Y/y)." <<
endl;
cin >> chChoice;
switch (chChoice)
{
case 'Y':
case 'y':
chChoice1 = 'e';
break;
default:
chChoice1 = ' ';
break;
}
return chChoice1;
}
#include "cPlayer.h"
char chChoice1 = ' ';
char chChoice3 = ' ';
cPlayer::cPlayer()
{
}
cPlayer::~cPlayer()
{
}
void cPlayer::fMenu()
{
// char chChoice3 = ' '; : Error here, It should not be local variable.
chChoice3 = ' ';
do
{
cout << "\n\t--Menu--" << endl;
cout << "1) Enter Player Name" << endl;
cout << "2) Select Player's Team" << endl;
cout << "3) Display Player Info" << 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 != 'e');
}
void cPlayer::fSelectTeam()
{
//chChoice2 is a character variable
char chChoice2 = ' ';
while (true)
{
cout << "Please select your team 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 GET LINE
}
char cPlayer::fVerifyExit()
{
char chChoice = ' ';
system("cls");
cout << "Do you want to exit (Y/y)." << endl;
cin >> chChoice;
switch (chChoice)
{
case 'Y':
case 'y':
chChoice1 = 'e';
break;
default:
chChoice1 = ' ';
break;
}
return chChoice1;
}
your verifyExit method changes the global variable, while in the menu function, you use the local variable.. And do not read the global variable.. hence in menu function the while loop keeps running always. let me know if any issues.
Hello i am having a bit of trouble with a verified exit for my program. For...
Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...
Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...
i am having issues correcting an error in my program here is my code: #include <iostream> // define libraries #include <fstream> using namespace std; // Variable definitions: ifstream infp; // file handler enum Tokens {INT_LIT, IDENT, ASSIGN_OP, ADD_OP, SUB_OP, MUL_OP, DIV_OP, LEFT_PAREN, RIGHT_PAREN, LETTER, DIGIT, UNKNOWN,ENDFILE}; Tokens nextToken; // nextToken read from the file. int charClass; // char class char lexeme [100]; // number of characters per line char nextChar; // next char read from the file int lexLen; //...
EXPLAIN HOW THIS PROGRAM WORKS, USING DEV C++ #include <iostream> #include <cmath> #define PI 3.1415926535897 using namespace std; typedef struct ComplexRectStruct { double real; double imaginary; } ComplexRect; typedef struct ComplexPolarStruct { double magnitude; double angle; } ComplexPolar; double radToDegree (double rad) { return (180.00 * rad) / PI; } double degToRadian (double deg) { return (deg * PI) / 180; } ComplexPolar toPolar (ComplexRect r) { ComplexPolar p; p.magnitude = round(sqrt(pow(r.real,...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
This is just a partial C++ code. I am having a problem with the getline(cin, variable) statement of my code. Please run the code for yourself and see that it doesn't let you enter the full name. It skips the prompt to enter the name and goes straight to the next cout statement. I can't use cin alone because I need to capture and store both the first name followed by space followed by last name. I was trying to...
Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...
Hey, i was just wondering how i would calculate over time pay in c++ visual studio 2017? what i have right now is either returning 0 for some reason or being skipped over? im also wondering about the federal tax as well because that also doesn't seem to work, any help is greatly appreciated! these are my variables char chChoice = ' '; int intempID = 0; int intHours = 0; int intOThours = 0; float flOTrate = 0; float...