Skip to content

Instantly share code, notes, and snippets.

@faisal95bd
Last active August 14, 2022 07:12
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 faisal95bd/8bfdc997b1109c3681a2f7dcfdcca57e to your computer and use it in GitHub Desktop.
Save faisal95bd/8bfdc997b1109c3681a2f7dcfdcca57e to your computer and use it in GitHub Desktop.
Number guessing game between 2 players
#include <stdio.h>
int main() {
int X, n1, n2, n3, i;
printf("Player 1 - Please enter your secret number: ");
scanf("%d", &X);
printf("Player 2 - Please enter your first guess now: ");
scanf("%d", &n1);
if (X == n1) {
printf("Right, Player-2 wins!");
exit(0);
}
else {
printf("Wrong, 2 Chance(s) left!\n");
}
printf("Player 2 - Please enter your second guess now: ");
scanf("%d", &n2);
if (X == n2) {
printf("Right, Player-2 wins!");
exit(0);
}
else {
printf("Wrong, 1 Chance(s) left!\n");
}
printf("Player 2 - Please enter your final guess now: ");
scanf("%d", &n3);
if (X == n3) {
printf("Right, Player-2 wins!");
}
else {
printf("Player-1 wins!");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment