Write a program for a match-stick game between the computer and a user. Rules for the game are as follows: a. There are 21 match-sticks. b. A player can pick up only upto four sticks at a time. c. The total number of sticks picked up by both the players in a single turn should be equal to five. d. The player who picks up the last stick is the loser. e. The user should play first..

#include <stdio.h>

int main(void)
{
int sticks = 21, upick;

do
{
printf( "\nSticks on board : %d ", sticks );
printf( "\nMake your pick [1-4] : " );
scanf( "%d", &upick );

if( upick < 1 || upick > 4 )
{
printf( "\No cheating please !!" );
continue;
}

printf( "\nYou Picked %d\nI pick %d", upick, (5-upick) );
sticks -= 5;

} while( sticks > 1 );

printf( "\nYou pick the last stick. You LOOSE" );
printf( "\nThanks for playing. Better luck next time" );

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin