Monday, September 27, 2010

Match stick game

Matchstick Game using C Programming

Write a program for a matchstick game being played between the computer and a user.
Your program should ensure that the computer always wins. Rules for the game are as follows:

-There are 21 matchsticks.
-The computer asks the player to pick 1, 2, 3 or 4 matchsticks.
-After the person picks, the computer does its picking.
-Whoever is forced to pick up the last matchstick loses the game.


-There are 21 matchsticks.
-Whoever is forced to pick up the last matchstick loses the game.
So the last one is special, so it's all about how to get rid of 20 matches in pairs of turns.

-The computer asks the player to pick 1, 2, 3 or 4 matchsticks.
So if we reduce the total by 5 each round, the sequence will go
21 16 11 6 1
In effect, whatever number the user picks (n), the computer picks 5-n



#include<stdio.h>
main()
{

int matchsticks=21usercomputer;

printf("Do not enter Invalid Numbers.\nNumbers above 4 are invalid.");

printf("\nIf you do so, the computer automatically wins.");

while (matchsticks>=1)
{

printf("\nNumber of matchsticks available right now is %d."matchsticks);

printf("\n\nYour Turn...\n\n\n");

printf("\nPick up the matchstick(s)-- (1-4): ");
scanf ("%d"&user);

if (user>4)

{
printf("Invalid Selection");
break;
}

computer=5-user;

printf("\nComputer's Turn..\n" );
printf("\nComputer chooses:%d"computer);

matchsticks=matchsticks-user-computer;
continue;

if(matchsticks==1)

break;
}

matchsticks--;
printf("\nComputer Wins");

}

6 comments:

  1. I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit. gamerbolt.com

    ReplyDelete
  2. I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create such a great informative website. fortnite v bucks gratuit

    ReplyDelete
  3. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. 안전놀이터

    ReplyDelete
  4. Quickly this site might undoubtedly become well-known among most blogging and site-building people, for that painstaking posts as well as critiques. 메이저사이트

    ReplyDelete
  5. Some truly wonderful work on behalf of the owner of this internet site , perfectly great articles . visit blog

    ReplyDelete
  6. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! esc online bonus

    ReplyDelete