Each player will have the chance to pick up as few as 1 chip and at most half of the pile of chips. This will continue until one of the players gets the last chip. Whomever gets the last chip is the winner of the game.
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main ()
{
int totalchips;
int maxchips;
int chips;
string current;
string player1;
string player2;
cout << "Rules: The game starts with a pile of chips."<<endl;
cout << " Each player may only take at most half of the chips."<<endl;
cout << " The player that gets the last chip wins. Good luck!"<<endl;
cout<< endl;
cout << "Player 1 please enter your first name:";
cin >> player1;
cout << "Player 2 please enter your first name:";
cin >> player2;
cout << endl;
cout <<"How many chips would you like to start with?";
cin >> totalchips;
current = player1
cout << endl << current << " how many of the remaining " << totalchips << " chip(s) would you like ("<<maxchips<< " max): ";cin >> chips;
while (chips > maxchips || chips <=0)
{
cout <<"invalid number of chips. Try again:"<<endl;
cin >> chips;
}
if(current == player1)
{
current = player2;
}
else
{
current = player1;
}
while (totalchips>=0)
{
maxchips=totalchips/2;
}
if (totalchips%2==1)
{
maxchips+=1;
}
if (totalchips == 0)
{
cout << " Congratulations "<<current << "! You won!"endl;
}
system ("pause");
return 0;
}
the line i highlight in red is where i got an error message and i can't figure out whats the problem