Skip to content

Instantly share code, notes, and snippets.

@Redeem-Grimm-Satoshi
Created March 25, 2020 17:39
Show Gist options
  • Save Redeem-Grimm-Satoshi/ff6c4135f85b60de11f2501561e9d959 to your computer and use it in GitHub Desktop.
Save Redeem-Grimm-Satoshi/ff6c4135f85b60de11f2501561e9d959 to your computer and use it in GitHub Desktop.
Rock-Paper-Scissor Game Written In C
/**
*Author: Redeem Grimm
*File Name: RPS.c
*Purpose: Play Rock, Paper, Scissors with the user
*
*/
#include <stdio.h>
int main(){
int ROCK, PAPER, SCISSORS, computer, user;
ROCK = 0;
PAPER = 1;
SCISSORS = 2;
srand ( time(NULL) );
computer = rand()%3;
printf("Choose wisely: Enter 0 for ROCK, 1 for PAPER, or 2 for SCISSORS. ");
scanf("%d",&user);
// 1. this code will tell if the computer throws ROCK. add code to tell
// you when the computer throws SCISSORS and PAPER. It will be very similar.
if(computer == ROCK){
printf("Computer: The computer throws ROCK\n");
}else if(computer==SCISSORS){
printf("Computer: The computer throws SCISSORS\n");
}else{
printf("Computer: The computer throws PAPER\n");
}
// 2. this is the code to determine who wins if the user picks ROCK. Write the
// code below it to handle if the user has PAPER and if the user has SCISSORS.
// the code will look very similar.
if(user == ROCK){
if(computer == PAPER){
printf("Rock vs Paper: You lose, PAPER covers ROCK!\n");
system("pause");
main();
}
else if(computer == ROCK){
printf("Rock vs Rock: It's a tie, we both have ROCK!\n");
main();
}
else{ //computer == SCISSORS
printf("Rock vs SCISSORS: You win, ROCK breaks SCISSORS!\n");
main();
}
}
if(user==SCISSORS){
if(computer == PAPER){
printf("Scissors vs Paper: You Won, SCISSORS cuts PAPER!\n");
main();
}
else if(computer == ROCK){
printf("Scissors vs Rock: You Lose, ROCK breaks SCISSORS\n");
main();
}
else{ //computer == SCISSORS
printf("Scissors vs Scissors: It's a tie, We both have SCISSORS!\n");
main();
}
}
if(user==PAPER){
if(computer == PAPER){
printf("Paper vs Paper: It's a tie, We both have PAPER\n");
main();
}
else if(computer == ROCK){
printf("Paper vs Rock: You Won, PAPER covers ROCK\n");
main();
}
else{ //computer == SCISSORS
printf("Paper vs Scissors: You Lose, SCISSORS cuts PAPER\n");
main();
}
}
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment