diff --git a/ActualChips.cpp b/ActualChips.cpp index dcea631..0315738 100644 --- a/ActualChips.cpp +++ b/ActualChips.cpp @@ -1,14 +1,14 @@ -#include +#include #include #include #include -using std::string; -using std::ofstream; -using std::cout; using std::cin; -using std::ios; +using std::cout; using std::endl; +using std::ios; +using std::ofstream; +using std::string; const float MAX_TURN = .5; const int MAX_CHIPS = 100; @@ -38,13 +38,13 @@ int main() char userChoice; string playerNames[2]; - //Output file variables + //Output file variables ofstream outFile; outFile.open("Winners.txt", ios::app); - + //seed the random number generator srand(time(0)); - + //ask the players for their names, then store in an array getUserNames(playerNames); player1.name = playerNames[0]; @@ -52,29 +52,28 @@ int main() player1.numWins = 0; player2.numWins = 0; - //start the game with a random number of chips in the pile do { - chipsInPile = (rand() % MAX_CHIPS) + 1; + chipsInPile = (rand() % MAX_CHIPS) + 1; - cout << "This round will start with " << chipsInPile << " chips in the pile\n"; + cout << "This round will start with " << chipsInPile << " chips in the pile\n"; gameOver = false; moveCounter = 0; while (gameOver == false) - { + { chipsTaken = askMove(player1Turn, chipsInPile, playerNames); - chipsInPile = chipsInPile - chipsTaken; - cout << "There are " << chipsInPile << " left in the pile\n"; - player1Turn = !player1Turn; - moveCounter++; - if (chipsInPile == 0) - { - gameOver = true; - cout << FindPlayerName(playerNames, player1Turn) << ", congratulations you won" << endl; - outFile << FindPlayerName(playerNames, player1Turn) << " won in " << moveCounter << " moves" << endl; - } - } + chipsInPile = chipsInPile - chipsTaken; + cout << "There are " << chipsInPile << " left in the pile\n"; + player1Turn = !player1Turn; + moveCounter++; + if (chipsInPile == 0) + { + gameOver = true; + cout << FindPlayerName(playerNames, player1Turn) << ", congratulations you won" << endl; + outFile << FindPlayerName(playerNames, player1Turn) << " won in " << moveCounter << " moves" << endl; + } + } if (FindPlayerName(playerNames, player1Turn) == playerNames[0]) { player1.numWins = player1.numWins + 1; @@ -83,7 +82,7 @@ int main() { player2.numWins = player2.numWins + 1; } - cout << "\nDo you wish to play again? (Y/N)" << endl; + cout << "\nDo you wish to play again? (Y/N)" << endl; cin >> userChoice; userChoice = toupper(userChoice); if (userChoice == 'N') @@ -91,7 +90,7 @@ int main() cout << player1.name << " had " << player1.numWins << " total wins this round" << endl; cout << player2.name << " had " << player2.numWins << " total wins this round" << endl; } - }while ( userChoice == 'Y'); + } while (userChoice == 'Y'); outFile.close(); } @@ -108,44 +107,44 @@ void getUserNames(string players[]) string FindPlayerName(string names[], bool playerTurn) { - if (playerTurn == true) - return names[0]; - else - return names[1]; + if (playerTurn == true) + return names[0]; + else + return names[1]; } int askMove(bool player1Turn, int chipsInPile, string names[]) { - int chipsTaken; - int maxPerTurn = MAX_TURN * chipsInPile; - do + int chipsTaken; + int maxPerTurn = MAX_TURN * chipsInPile; + do { - cout << FindPlayerName(names, player1Turn) << " How many chips would you like?\n"; - - cout << "You can take up to "; - if (( maxPerTurn ) == 0) - { - cout << " 1\n"; - } - else - { - cout << maxPerTurn << endl; - } - if (FindPlayerName(names, player1Turn) == "AI") + cout << FindPlayerName(names, player1Turn) << " How many chips would you like?\n"; + + cout << "You can take up to "; + if ((maxPerTurn) == 0) { - if (maxPerTurn == 0) - { - chipsTaken = 1; - } - else - { - chipsTaken = (rand() % maxPerTurn) + 1; - } - } - else - { - cin >> chipsTaken; - } - }while ((chipsTaken > maxPerTurn ) && (chipsInPile > 1)); + cout << " 1\n"; + } + else + { + cout << maxPerTurn << endl; + } + if (FindPlayerName(names, player1Turn) == "AI") + { + if (maxPerTurn == 0) + { + chipsTaken = 1; + } + else + { + chipsTaken = (rand() % maxPerTurn) + 1; + } + } + else + { + cin >> chipsTaken; + } + } while ((chipsTaken > maxPerTurn) && (chipsInPile > 1)); return chipsTaken; -} \ No newline at end of file +} diff --git a/ActualChips.exe b/ActualChips.exe index 5d7f463..ffd7ba2 100644 Binary files a/ActualChips.exe and b/ActualChips.exe differ diff --git a/Winners.txt b/Winners.txt deleted file mode 100644 index e69de29..0000000