All pastes #79923 Raw Edit

Someone

public text v1 · immutable
·published 2006-07-05 21:47 UTC
rendered paste body
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
	char answer;		//setting up variable for Yes/No answer for playinh
	
	string name1, name2, 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<<"Player 1 please enter your first name: ";		//Player 1's name entered
				cin>> name1;
				cout<<"\nPlayer 2 please enter your first name: ";		//Player 2's name entered
				cin>> name2; 
				}
			}
	
	int chipCount = 1000;
	
	int inputNum;	 
	
	while(1)
                {               
                cout << endl << name1 << " how many of the remaining " << chipCount << " chip(s) would you like (" << chipCount/2 << " max)?";
                cin >> inputNum;
                        
                while(inputNum > chipCount/2)
                        {   
                        cout<<"Error: Chips taken must be at most half of the chips. (" << chipCount/2 << "max) ";
                        cin >> inputNum;                     
                        }
				
				if(inputNum <= 0)
						{
						cout<<"Error: Only postive integers are acceptable entries. (" << chipCount/2 << "max) ";		
						}
                if(inputNum <= chipCount/2)
                        {
                        chipCount=chipCount-inputNum;
                        }  
						
				if(chipCount%2!=0)
					{
					chipCount++;
					}  
				if(player=name1)
					{
					player=name2;
					}
				if(chipCount = 0)
					{
					cout<<"\nCongratulations "<<player<<"! You won!";
					}    
                } 
			
			
}