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

Rock, Paper, Scissors. Write a program that lets a user play \"Rock, Paper, Scis

ID: 642937 • Letter: R

Question

Rock, Paper, Scissors. Write a program that lets a user play "Rock, Paper, Scissors" against the computer. The program should ask the user to choose one of the three choices, and then the computer randomly picks one (without knowing what the user has chosen).

For this problem, the user should be asked to enter an integer: 0 for rock, 1 for paper, or 2 for scissors. Rock beats scissors, scissors beats paper, paper beats rock. The program should say who wins, and then keep playing until someone (the user or the computer) has won 10 rounds. The computer needs to keep track of the current score and should also display it before each round.

Explanation / Answer

#include<stdio.h>
void main()
{
int i,x,r,u=0,c=0;
printf("Enter 0 for rock, 1 for paper, or 2 for scissors ");
for(i=0;i<10;)
{
printf("Enter: ");
scanf("%d",&x);
srand(time(NULL));
r=rand()%3;  
if(r==0)
printf("computer chosen :rock ");
if(r==1)
printf("computer chosen: paper ");
if(r==2)
printf("computer chosen: scissors ");


if(r==x)
printf("both have chosen same thing no winner ");

if(r==2 && x==0)
{
printf("User won ");
u++;
}
if(x==2 && r==0)
{
printf("Computer won ");
c++;
}
if(x==2 && r==1)
{
printf("User won ");
u++;
}
if(r==2 && x==1)
{
printf("Computer won ");
c++;
}
if(x==1 && r==0)
{
printf("User won ");
u++;
}
if(r==1 && x==0)
{
printf("Computer won ");
c++;
}


printf("Status: User:%d Computer:%d ",u,c);

if(u==10)
{
printf("User won 10 rounds:The game is over");
break;
}
if(c==10)
{
printf("Computer won 10 rounds:The game is over");
break;
}
}
}

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