-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_stick_game.c
51 lines (43 loc) · 1.16 KB
/
match_stick_game.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int ms=21,user,computer;
while(1)
{
printf("Number of match sticks left = %d\n",ms);
printf("\nPick 1,2,3 or 4 matches ");
scanf("%d",&user);
if(user > 4 || user < 1)
{
continue;
}
ms = ms - user;
printf("\nUser picked %d match sticks\n",user);
printf("\nNumber of match sticks left = %d\n",ms);
computer = 5 - user;
printf("\nComputer picked %d match sticks\n",computer);
printf("\nNumber of match sticks left = %d\n\n",ms);
ms = ms - computer;
if(ms == 1)
{
printf("Number of match sticks left = %d\n\n",ms);
printf("\nYou have lost the game \nComputer won!\n");
break;
}
}
}
/*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.*/
/*
Note:Computer will always win😂
*/