Created
November 11, 2018 08:39
-
-
Save ThePratikSah/1b8e3dc3d511e1eed104e51498a702b1 to your computer and use it in GitHub Desktop.
Here is the code for MatchStick game. Hope you'll enjoy playing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
int match = 21, comp, user, choice, c = 0; | |
printf(“Game Rules:\nYou have to pick 1, 2, 3 or 4 matchstick at a time.”); | |
printf(“\nAfter your picking, computer does its picking.”); | |
printf(“\nWhoever is forced to pick the last matchstick looses the game.”); | |
printf(“\nPress 1 to start the game:”); | |
scanf(“%d”, &choice); | |
while (choice == 1) { | |
do { | |
printf(“\nPick any number of matchstick:”); | |
scanf(“%d”, &user); | |
if (user > 4) { | |
printf(“You picked more than 4 stick, you loose.\n”); | |
c++; | |
break; | |
} | |
match = match — user; | |
comp = 5 — user; | |
printf(“\nComputer picks %d matchstick.\n”, comp); | |
match = match — comp; | |
} while (match > 1); | |
if (c == 0) { | |
printf(“\nYou picked the last matchstick, so you loose.\n”); | |
break; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment