Skip to content

Instantly share code, notes, and snippets.

@saiedabbas93
Created August 13, 2019 22:31
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 saiedabbas93/074b0ed4adafae80048b17e68e8c79e4 to your computer and use it in GitHub Desktop.
Save saiedabbas93/074b0ed4adafae80048b17e68e8c79e4 to your computer and use it in GitHub Desktop.
STONE PAPER SCISSORS WITH THE COMPUTER
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
void main()
{
char player1[10];
int in1,in2;
printf("HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME\nWhat is player1's name?\n ");
scanf("%s",&player1);
printf("You will be playing with the computer which is player 2\n");
printf("%s , please follow the rules of the game\nPress 1 for stone\nPress 2 for paper\nPress 3 for scissors\n\n",player1);
printf("Now let us start the game\n");
printf("%s is it STONE 1, PAPER 2 OR SCISSORS 3\n",player1);
scanf("%d",&in1);
int i; /* loop variable */
srand(time(NULL)); /* time(NULL) returns time in seconds since
the epoch; this seeds the random number
function with a new number.
Only call this once per program. */
for (i=0; i<1; i++)
{
in2=rand()%4; /* returns values in the range 1-3 */
if (in2==0)
{
for ( i = 0; i < 1; i++)
{
in2=rand()%4;
}
}
printf("The input of computer is %d\n", 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,player1);
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("Computer has won this game!!!!");
}
@saiedabbas93
Copy link
Author

OUTPUT:
HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME
What is player1's name?
JOHN
You will be playing with the computer which is player 2
JOHN , please follow the rules of the game
Press 1 for stone
Press 2 for paper
Press 3 for scissors

Now let us start the game
JOHN is it STONE 1, PAPER 2 OR SCISSORS 3
3
The input of computer is 1
Computer has won this game!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment