Hello,
I am struggling to find out why the IDE says that getPlayerID (line 25) is undefined. I don't understand how it's undefined and was wondering if someone could point out my error.
Now I feel very silly I did not catch that mistake....it's so obvious. I think I need more sleep or more coffee....or both! Thank you everyone for your help :)
Alright so now I have a new problem with this code. I am struggling to figure out how to write a function that will allow the players to type in the number of games they have played. I have tried adding this to the code that's above:
.cpp file
1 2 3 4
int playerOneTosses;
cout << playerOne.getPlayerName << "Please type in your total number of tosses: ";
getline(cin, playerOneTosses);
playerOne.getPlayerTosses(playerOneTosses);
.h file
1 2 3 4 5 6 7 8 9 10 11 12 13
private:
int playerTosses;
//---------------------------------------------------
public:
int getPlayerTosses() const
{
return playerTosses;
}
As I was typing it I felt that it was wrong and sure enough it is. Could someone guide me on what to do or direct me to a tutorial or resource that can help me figure this one out?
#include <string>
#include <iostream>
#include "FrisbeeGolfer.h"
usingnamespace std;
int main()
{
string nameOfPlayer;
FrisbeeGolfer playerOne;
cout << "- First Frisbee Golfer, please type in your first and last name: " << endl;
getline(cin, nameOfPlayer);
playerOne.setPlayerName(nameOfPlayer);
cout << endl;
playerOne.welcomeMessage();
string playerOneID;
cout << "\nPlease enter your Player ID: ";
getline(cin, playerOneID);
playerOne.setPlayerID(playerOneID);
cout << "\nYour Player ID is " << playerOne.getPlayerID() << ".\n" << endl;
cout << "***************************************************************************" << endl;
//-----------------------------------------------------------------------------------------------
FrisbeeGolfer playerTwo;
cout << "\n- Second Frisbee Golfer, please type in your first and last name: " << endl;
getline(cin, nameOfPlayer);
playerTwo.setPlayerName(nameOfPlayer);
cout << endl;
playerTwo.welcomeMessage();
string playerTwoID;
cout << "\nPlease enter your Player ID: ";
getline(cin, playerTwoID);
playerTwo.setPlayerID(playerTwoID);
cout << "\nYour Player ID is " << playerTwo.getPlayerID() << ".\n" << endl;
//-----------------------------------------------------------------------------------------------
int playerOneTosses;
cout << playerOne.getPlayerName << "Please type in your total number of tosses: ";
cin >> playerOneTosses;
// playerOne.getPlayerTosses(playerOneTosses);
cin.ignore();
cin.get();
return 0;
};
Looking through your code I don't believe you ever actually set the player tosses. So you are trying to return something that hasn't been given a value.
P.S. Don't useusingnamespace std; in a header file. It's not that good of a practice.
The short answer to the problem with line 49 is it should be playerOne.setPlayerTosses(playerOneTosses); not get. As Too Explosive said: you never set the playerTosses variable in the class.