From if else to switch statement
Hi, I was wondering how you would put this if else statement to a switch statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void PlayerDB::AddPlayer(const Player& avatarPlayer)
{
char * playerName = new char[avatarPlayer.lenName()];
Player * player = NULL;
avatarPlayer.getName(playerName);
if(DBtable.retrieve(playerName, player))
{
cout << "Attempting to add player \"" << playerName << "\" to the database -- Failed." << endl;
}
else
{
DBtable.insert(playerName, avatarPlayer);
cout << "Attempting to add player \"" << playerName << "\" to the database -- Success!" << endl;
}
delete[] playerName;
}
|
You wouldn't. A switch is where you have multiple different results. If you have only 2 results, if/else makes much more sense.
Topic archived. No new replies allowed.