Last active
August 14, 2022 07:12
-
-
Save faisal95bd/8bfdc997b1109c3681a2f7dcfdcca57e to your computer and use it in GitHub Desktop.
Number guessing game between 2 players
This file contains 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 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