Då de två if-satserna är nästintill identiska så kan/bör du skriva koden så att skillnaderna förs in via variabler. Kodduplicering bör i möjligaste mån undvikas.
if(currentPlayer == playerOne) //spelare ett-loop
{
std::cout << "There are " << matches << " to chose from." << '\n';
std::cout << "How many matches do you want to take, " << playerOne << ", 1 or 2? ";
std::cin >> remaining;
matches = matches - remaining;
std::cout << "Now there are " << matches << " matches remaining. ";
system ("PAUSE"); //spelare måste trycka på en tangent för att fortsätta
system("CLS");
currentPlayer = playerTwo;
}
else if(currentPlayer == playerTwo) //spelare två-loop
{
std::cout << "There are " << matches << " to chose from." << '\n';
std::cout << playerTwo << ", how many do you want to take? 1 or 2? ";
std::cin >> remaining;
matches = matches - remaining;
system ("PAUSE");
system("CLS");
currentPlayer = playerOne;
}
skrivs med fördel som
std::cout << "There are " << matches << " to choose from." << '\n';
// Använd currentPlayer, inte playerOne/playerTwo på nästa rad
std::cout << "How many matches do you want to take, " << currentPlayer << ", 1 or 2? ";
std::cin >> remaining;
matches = matches - remaining;
std::cout << "Now there are " << matches << " matches remaining. ";
system ("PAUSE"); //spelare måste trycka på en tangent för att fortsätta
system("CLS");
// Byt spelare vid draget
if(currentPlayer == playerOne) {
currentPlayer = playerTwo;
} else {
currentPlayer = playerOne;
}