Skip to content

Instantly share code, notes, and snippets.

@saiedabbas93
Last active January 8, 2022 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saiedabbas93/5c7a0af630847c38f2bfb13171793865 to your computer and use it in GitHub Desktop.
Save saiedabbas93/5c7a0af630847c38f2bfb13171793865 to your computer and use it in GitHub Desktop.
STONE/ROCK PAPER SCISSORS GAME BETWEEN TWO PLAYERS IN C PROGRAM
#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);
}
@saiedabbas93
Copy link
Author

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!!!!

@PablaOO7
Copy link

PablaOO7 commented Oct 2, 2020

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.

@saiedabbas93
Copy link
Author

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 :)

@23182810
Copy link

23182810 commented Jan 8, 2022

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