Question
I wrote a code that play rock, paper, scissors in with the user in C programming and put it below. How would I use my
I wrote a code that play rock, paper, scissors in with the user in C programming and put it below. How would I use my rock, paper, scissors code to do the rest of the 4 bullet points in C Programming in the image posted? Please if possible screenshot how it would look like with it compiled. Thanks.
#include
#include
#include
int main()
{
int userMove;
int computerMove;
srand(time(NULL));
printf("This is a rock, paper, and scissor game. Please enter a move(1=Rock, 2 =Paper, 3=Scissors):");
scanf("%d", &userMove);
printf(" Computer chooses ");
computerMove=1+rand()%3;
if(computerMove==1)
{
printf("Rock! ");
}
else if(computerMove==2)
{
printf("Paper! ");
}
else if(computerMove==3)
{
printf("Scissor! ");
}
else printf("Tie!");
//{
if ((userMove==1)&&(computerMove==1))
{
printf(" Tie!");
}
else if ((userMove==1)&&(computerMove==2))
{ printf(" User Wins!");
}
else if ((userMove==1)&&(computerMove==3))
{ printf(" Computer Wins!");
}
else if((userMove==2)&&(computerMove==1))
{ printf(" User Wins!");
}
else if((userMove==2)&&(computerMove==2))
{ printf(" Tie!");
}
else if((userMove==2)&&(computerMove==3))
{ printf(" Computer Wins!");
}
else if((userMove==3)&&(computerMove==1))
{ printf(" Computer Wins!");
}
else if((userMove==3)&&(computerMove==2))
{ printf(" User Wins!");
}
else if((userMove==3)&&(computerMove==3))
{ printf(" Tie!");
}
else
{ printf("You have select an invalid selection.");
}
}
Goals The goals for you to accomplish during class today are as follows: 1. Write your first function! Start with the code you wrote that plays Rock, Paper, Scissors with the user. Update this code to make a FUNCTION called ComputerMove that displays the computers move (randomly selected 1, 2, or 3) and returns it Write another FUNCTION called UserMove that asks the user for their move and returns their selection (1, 2, or 3) In your main(), call each function once and display the winner (or tie) Make sure your code compiles and runsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started