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

to have the user choose rock, paper or scissors. The computer will also randomly

ID: 3685852 • Letter: T

Question

to have the user choose rock, paper or scissors. The computer will also randomly choose. Then, figure out if who wins or if it was a tie. Then, ask if they want to play again and restart. Each time the game is over, print how many times the computer won, the player won, and ties. Feel free to use 1, 2 and 3 for rock, scissors and paper. We will be doing this through top down refinement. First, what are the things we have to do. Then we will keep breaking it down until we have a program. LANGUAGE IS IN C PROGRAMMING

Explanation / Answer

#include <stdio.h>

#include <conio.h>

main ()

{

char p1, p2;

clrscr ();

printf (" Enter Player 1: ");

p1=getche ();

printf (" Enter Player 2: ");

p2=getche ();

if (((p1=='p')||(p1=='P')) && ((p2=='R') || (p2=='r')))

{

   printf (" Player 1 Wins !");

   printf (" Paper Covers Rock");

}

else if (((p2=='p') || (p2=='P')) && ((p1=='r') || (p1=='R')))

{

printf (" Player 2 Wins !");

printf (" Paper Covers Rock");

}

else if (((p1=='r') || (p1=='R')) && ((p2=='s') || (p2=='S')))

{

printf (" Player 1 Wins !");

printf (" Rock Breaks Scissors");

}

else if (((p2=='r') || (p2=='R')) && ((p1=='s') || (p1=='S')))

   {

printf (" Player 2 Wins !");

printf (" Rock Breaks Scissors");

}

else if (((p1=='s') || (p1=='S')) && ((p2=='p') || (p2=='P')))

{

printf (" Player 1 Wins !");

printf (" Scissors Cut Paper");

}

else if (((p2=='s') || (p2=='S')) && ((p1=='p') || (p1=='P')))

{

printf ("Player 2 Wins !");

printf ("Scissors Cut Paper");

}

else if (p1==p2)

{

printf (" Nobody Wins !");

printf (" Both Of You Entered The Same Letters");

}

else {

printf (" Unknown Input Data!");

printf (" Enter Only Letters : P,S or R");

}

getch ();

}