I am making a program that will track golf stats so i need to make players. I made a function called
getPlayer(int playerNum);
and inside of it i have all of this code
switch(playerNum)
case 1: return(player1);break;
case 2: return(player2);break;
case 3: return(player3);break;
case 4: return(player4);break;
case 5: return(player5);break;
case 6: return(player6);break;
case 7: return(player7);break;
case 8: return(player8);break;
case 9: return(player9);break;
case 10: return(player10);break;
and in my playermanager.h
#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H
#include <string>
class playerManager
{
public:
playerManager();
std::string getPlayer(int playerNum);
private:
std::string player1;
std::string player2;
std::string player3;
std::string player4;
std::string player5;
std::string player6;
std::string player7;
std::string player8;
std::string player9;
std::string player10;
};
#endif // PLAYERMANAGER_H
Now when i run this i get the error
'player1' was not declared in this scope
And i also get the error
break statement not within loop or switch
and it goes on and on from player 1 to player 10.
I have intelized the the string by calling a file reader function. I am really new to c++ and i am probably doing something just stupidly wrong so if anyone could help please.
Thanks in advance!
Leaving out the codereview stuff –
did you by any chance implement
instead of
?
Also – the
switch:That aside – awful code. Imagine I’m your customer and tell you I want 11 players instead of 10. What then?