Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Name this program rpsls.c – The game of rock-paper-scissors was expanded so t

ID: 3671617 • Letter: 4

Question

4. Name this program rpsls.c – The game of rock-paper-scissors was expanded so that it now includes rockpaper-scissors-lizard-spock. The expansion was created by Sam Kass and Karen Bryla and made famous on the Big Bang Theory. See http://bigbangtheory.wikia.com/wiki/Rock_Paper_Scissors_Lizard_Spock for complete details. Your program should read the two player moves from the command line, as shown below, and print a message indicating the winner. You can assume that the first move (lizard in the case below) is for Player One, and the second move (paper in the case below) is for Player Two. ./a.out lizard paper You can also assume that the user will always enter a valid input for each player. That is, the word will be lowercase and will be one of “rock” or “paper” or “scissors” or “lizard” or “spock”. As it says, user must enter a valid input for both players, and not the computer.

Explanation / Answer

Program Plan:The program is mentioned below with corresponding comments .

Program:


//including header files
#include<stdio.h>
#include<conio.h>
#include<math.h> //we are using rand() method so we are including math.h

main() {
  int input,rand;
                                    char ch;
  int n = 1;
  printf("Hi lets play the Game");

  printf("Pick 1,2,3,4 or 5 for:");
  print("1-ROCK ,2-PAPER, 3-SCISSOR ,4-LIZARD,5-SPOCK");
  while (n != 0) {
   int r = 1, p = 2, sc = 3,l=4,sp=5; //r for Rock,p for paper,sc

for scissors,l for Lizard,,sp for Spock

   scanf("%d",&input); //reading the user input
   rand= rand() % 5 + 1; //generating the random

number.method returns 0 or1,2,3or 4.thats why we are adding 1
                                                          //comparing the system option with the user option by using

if..else structure   

                                                          if (rand == r) {
    if (input == r) {
     printf("Rock Vs. Rock :: TIE");
    } else if (input == p) {
     printf("Paper Vs. Rock: YOU WIN");
    } else if (input == sc) {
     printf("Scissor Vs. Rock: YOU

LOSE");
                                                                           else if(input==li)printf("Lizard Vs Rock:YOU

LOSE");
    else if(input==sp)printf("Spock Vs Rock:YOU

WIN");

    }
   } else if (rand == p) {
    if (input == r) {
     printf("rock Vs. paper:: YOU

LOSE");
    } else if (input == p) {
     printf("Paper Vs. Paper: TIE");
    } else if (input == sc) {
     printf("Scissor Vs. Paper: YOU

WIN");
                                                                           else if(input==li)printf("Lizard Vs paper:YOU

LOSE");
    else if(input==sp)printf("Spock Vs Paper:YOU

WIN");

    }
   } else if (rand == sc) {
    
    if (input == r) {
     printf("Rock Vs. Scissior :: YOU

WIN");
    } else if (input == p) {
     printf("Paper Vs. Scissor: YOU

LOSE");
    } else if (input == sc) {
     printf("Scissor Vs. Scissor: TIE");
                                                                           else if(input==l)printf("Lizard Vs Scissor:YOU

LOSE");
    else if(input==sp)printf("Spock Vs Scissor:YOU

WIN");

    }else if (rand == l) {
    if (input == r) {
     printf("Rock Vs. Lizard:: YOU

WIN");
    } else if (input == p) {
     printf("Paper Vs. Lizard: YOU

LOSE");
    } else if (input == sc) {
     printf("Scissor Vs. Lizard: YOU

WIN");
                                                                           else if(input==l)printf("Lizard Vs Lizard:TIE");
    else if(input==sp)printf("Spock Vs Lizard:YOU

LOSE");

    }else if (rand == sp) {
    if (input == r) {
     printf("Rock Vs. Spock :: YOU

LOSE");
    } else if (input == p) {
     printf("Paper Vs. Spock: YOU

WIN");
    } else if (input == sc) {
     printf("Scissor Vs. Spock: YOU

LOSE");
                                                                           else if(input==l)printf("Lizard Vs Spock:YOU

WIN");
    else if(input==sp)printf("Spock Vs Spock:TIE");

    }

   }


printf("Do you want to play again? Y/N");
scanf("%c",&ch);
    if(ch=='Y' ||ch='y'){
      n=1;
      printf("Rock, Paper,Scissor,Lizard,Spock");
    }
    else if(ch=='N' || ch=='n')printf("GOODBYE");
  
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote