Last active
January 8, 2022 16:50
-
-
Save saiedabbas93/5c7a0af630847c38f2bfb13171793865 to your computer and use it in GitHub Desktop.
STONE/ROCK PAPER SCISSORS GAME BETWEEN TWO PLAYERS IN C PROGRAM
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> | |
#include<conio.h> | |
void main() | |
{ | |
char player1[10],player2[10]; | |
int in1,in2; | |
printf("HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME\nWhat is player1's name?\n "); | |
scanf("%s",&player1); | |
printf("What is player2's name?\n "); | |
scanf("%s",&player2); | |
printf("%s and %s please follow the rules for the game\nPress 1 for stone\nPress 2 for paper\nPress 3 for scissors\n\n",player1,player2); | |
printf("Now let us start the game\n"); | |
printf("%s is it STONE 1, PAPER 2 OR SCISSORS 3\n",player1); | |
scanf("%d",&in1); | |
printf("%s is it STONE 1, PAPER 2 OR SCISSORS 3\n",player2); | |
scanf("%d",&in2); | |
if ((in1==1 && in2==1) || (in1==2 && in2==2) || (in1==3 && in2==3)) | |
printf("Neither %s nor %s won, it is a draw",player1,player2); | |
else if ((in1==1 && in2==3) || (in1==3 && in2==2) || (in1==1 && in2==3)|| (in1==2 && in2==1) || (in1==3 && in2==2) || (in1==1 && in2==3)) | |
printf("Congrats %s! You won!!!!",player1); | |
else if ((in1==1 && in2==2) || (in1==3 && in2==1) || (in1==1 && in2==2)|| (in1==2 && in2==3)) | |
printf("Congrats %s! You won!!!!",player2); | |
} |
Code line 21:
printf("Neither %s nor %s won, it is a draw",player1,player1);
Your code perfectly fine, but there is a small typo error at the line 21 of the code: mentioned in the bold letters above it will be player 2.
Code line 21:
printf("Neither %s nor %s won, it is a draw",player1,player1);Your code perfectly fine, but there is a small typo error at the line 21 of the code: mentioned in the bold letters above it will be player 2.
Thank you for pointing out the error. I will chnage it :)
If the 2nd person was a computer, how would it be written?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME
What is player1's name?
Alex
What is player2's name?
John
Alex and John please follow the rules for the game
Press 1 for stone
Press 2 for paper
Press 3 for scissors
Now let us start the game
Alex is it STONE 1, PAPER 2 OR SCISSORS 3
1
John is it STONE 1, PAPER 2 OR SCISSORS 3
2
Congrats John! You won!!!!