Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

# C++ Game help

### #1 AJwest Posted 09 February 2010 - 01:52 PM

AJwest

New Member

• Member
• 1 posts
Write a two person chip game. The game will start with a pile of chips.
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;

cin >> player1;

cin >> player2;

cout << endl;

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
• 0

### #2 InsaneKaos Posted 09 February 2010 - 08:53 PM

InsaneKaos

Member

• Member
• 120 posts
current = player1;<-----

cout << endl << current << " how many of the remaining " << totalchips << " chip(s) would you like ("<<maxchips<< " max): ";cin >> chips;

Maybe that is the problem.
• 0

### #3 OpenOutcome Posted 13 February 2010 - 11:44 AM

OpenOutcome

Member

• Member
• 640 posts
Hello,

InsaneKaos is right. Also:

if (totalchips == 0)
{
cout << " Congratulations "<<current << "! You won!" << endl;

Good luck,

-Jason
• 0

### #4 TheBug Posted 16 February 2010 - 01:49 PM

TheBug

Member

• Member
• 28 posts
I do not see any loop for the game to carry on until there are no chips left. You should check the algorithm again.
• 0

### Similar Topics

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users