#include #include using namespace std; int main () { char answer; //setting up variable for Yes/No answer for playinh string name1 = ""; string name2 = ""; string player = ""; //Strings cout<<"Rules: The game starts with 1000 chips. Each player may only take at most half of the chips. The player that gets the last chip wins. Good luck!" <<"\nWould you like to play the chip game (y or n)? "; //Rules cin>>answer; //Answer if you want to play if (answer == 'n' || answer == 'N') //Both choices for not wanting to play { cout<< "Goodbye"; exit(0); //exits program if choice is no } else { if (answer == 'y' || answer == 'Y') //continues on with game if Yes { cout<<"\nPlayer 1 please enter your first name: "; //Player 1's name entered cin>> name2; cout<<"\nPlayer 2 please enter your first name: "; //Player 2's name entered cin>> name1; } } int chipCount = 1000; int inputNum; player = name1; while(1) { if(player == name1) //switches players { player = name2; } else { player = name1; } cout << endl << player << " how many of the remaining " << chipCount << " chip(s) would you like (" << ((chipCount / 2) + (chipCount % 2)) << " max)?"; //displays message cin >> inputNum; while(inputNum > ((chipCount / 2) + (chipCount % 2))) //limits chips taken { cout<<"Error: Chips taken must be at most half of the chips. (" << ((chipCount / 2) + (chipCount % 2)) << "max) "; cin >> inputNum; } if(inputNum <= 0) //limits to only positive integers { cout<<"Error: Only positive integers are acceptable entries. (" << ((chipCount / 2) + (chipCount % 2)) << "max) "; cin >> inputNum; } if(inputNum <= ((chipCount / 2) + (chipCount % 2)) && inputNum > 0) //subtracts input from chip count { chipCount=chipCount-inputNum; //chip formula } if(chipCount < 1) { break; //breaks loop once the last chip is taken } } if(player == name1) //switches player to display the winner { player = name2; } else { player = name1; } if(chipCount < 1) { cout<<"\nCongratulations "<