Skip to content

Instantly share code, notes, and snippets.

@ThePratikSah
Created November 11, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThePratikSah/1b8e3dc3d511e1eed104e51498a702b1 to your computer and use it in GitHub Desktop.
Save ThePratikSah/1b8e3dc3d511e1eed104e51498a702b1 to your computer and use it in GitHub Desktop.
Here is the code for MatchStick game. Hope you'll enjoy playing.
#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