3 Replies - 7466 Views - Last Post: 29 April 2010 - 05:55 AM Rate Topic: -----

#1 bhuvaneswari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-June 08

match stick game

Posted 29 April 2010 - 05:09 AM

program for a match stick game 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 match –stick
• The computer asks the player to pick 1,2,3 or 4 match strick.
• After the person pick, the computer does is picking.
• Whoever is forced to pick up the last match – stick loses the game.


#include<stdio.h>
main()
{

int matchsticks=21, user, computer;

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");

}



i need it to enhance.. any other logics,,,,,,,,,,

This post has been edited by bhuvaneswari: 29 April 2010 - 05:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: match stick game

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: match stick game

Posted 29 April 2010 - 05:34 AM

ok... and this is our problem because...???

again please read the rules before you post. We will not do your work for you. You need to show some effort to solve the problem on your own.

You need to have a clear question. stating, "i need it to enhance" is great - I wish you al the luck in the world with that, but I can't really help. What do you mean by enhance? Do you want graphics? Do you want to make it into a flash app that communicates with a server with a backend database?

Show some effort, ask clear questions.

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 codermonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 15-April 10

Re: match stick game

Posted 29 April 2010 - 05:47 AM

on the logic part there is a similar problem out there that is based on what the user picks for example if the user picks 1 the CPU picks 4, user picks 2 CPU picks 3, user picks 3 CPU picks 2, user picks 4 CPU picks 1. therefore forcing the last match stick. but remember what the user and cpu pick must add up to 5 (hint). and that is how it works. sorry to D.I.C if i violated any rules by giving him the logic. but he still has to figure out how to implement it. Its a simple way to force the last match stick as long as the user ALWAYS goes first.so write up a quick snippet and if you are still stuck then i will help you out further.

Sorry didnt see that you already knew the adds up to five part. ask a better question and ill be happy to help as well as some people here more experinced at this than i am.

This post has been edited by codermonk: 29 April 2010 - 05:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 codermonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 15-April 10

Re: match stick game

Posted 29 April 2010 - 05:55 AM

sorry about the double post but to the OP your code runs fine. and it always wins as it should. i dont see why you are needing any help. you should include a way for the user to play again as well as a way to see the results of the game displayed on the screen after the game. but following the adds to 5 rule the computer will always win.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1