23 Tooth picks

closed account (DG6DjE8b)
The game of “23” is a two-player game that begins with a pile of 23 toothpicks. Players take turns,
withdrawing either 1, 2, or 3 toothpicks at a time. The player to withdraw the last toothpicks loses the
game. Write a human vs. computer program that plays “23”. The human should always move first. When
it is the computer’s turn , it should play according to the following rules:
1) If there are more than 4 toothpicks left, then the computer should withdraw 4-x toothpicks, where x
is the number of toothpicks the human withdrew on the previous turn.
2) If there are 2 to 4 toothpicks left, then the computer should withdraw enough toothpicks to leave 1.
3) If there is 1 toothpick left, then the computer has to take it and loses.


THis is what i got so far.. but its not saying who won at the end

int compick, humpick;
int toothpicks= 23;


do{
cout << "Please pick up your toothpick(s), 1,2,or 3."<<endl;
cin >> humpick;

toothpicks = toothpicks - humpick;
cout << " toothpick(s) remaining" << toothpicks << endl;

if (toothpicks == 1 && compick == 1) {
cout << "Human Won" << endl;
break;
}

if (toothpicks > 4) {
compick = 4 - humpick;
cout << "The computer took " << compick << " toothpick(s)" << endl;
} else if (toothpicks == 2) {
compick = 1;
cout << "The computer took " << compick << " toothpick(s)" << endl;
} else if (toothpicks == 3) {
compick = 2;
cout << "The computer took " << compick << " toothpick(s)" << endl;
} else if (toothpicks == 4) {
compick = 3;
cout << "The computer took " << compick << " toothpick(s)" << endl;
} else if (toothpicks == 1) {
compick = 1;
cout << "The computer took " << compick << " toothpick(s)" << endl;
}

toothpicks = toothpicks - compick;
cout << " toothpick(s) remaining " << toothpicks <<endl;

if (toothpicks == 1 && humpick == 1) {
cout << "The computer WON!" << endl;
break;
}
if (humpick>3 || humpick <0)
{
cout<< "Please enter a correct value." <<endl;

continue;
}

if (toothpicks <0){
cout<<"Game will restart, now. (Enter 4 to quit)"<< endl;
cin>>humpick;
toothpicks=23;
continue;
}

}

while (humpick != 4);
}
Please use code tags to make your code readable:

http://www.cplusplus.com/articles/z13hAqkS/

EDIT: I can see that people have asked you to do this in your previous threads, and you've ignored them completely. If you're not going to make the slightest effort to help us read your code, why should we bother to make the slightest effort to help you?
Last edited on
Topic archived. No new replies allowed.