I need to add a line that prints "Not a legal move!" if the user enters something that isn't R, P or S and have the game continue. Here is my code.
#include <stdio.h>
#include <stdlib.h>
//declare variables
int main() {
int randSeed;
int numGames;
int userScore=0;
int compScore=0;
char userChoice;
int tieScore=0;
char comp;
//welcome and user input
printf("Starting the CPSC 1011 Rock, Paper, Scissors Game!\n\n");
printf("Enter a random seed between 0 - 100:");
scanf("%d", &randSeed);
srand(randSeed);
printf("\nEnter the number of matches to play: ");
scanf("%d", &numGames);
//loop for number of games and letter check
for(int i=0; i<numGames; i++) {
printf("\n\tMatch %d: Enter R for rock, P for paper, or S for scissors: ",(i+1));
while(1){
scanf("%c", &userChoice);
if((userChoice=='R')|| (userChoice=='P')|| (userChoice=='S')){
break; }
}
//computer selection
comp="RPS"[random()%3];
// scoring
if(userChoice=='R'){
if(comp=='R'){
printf("\tThe computer chose rock. You tied.");
tieScore++;
}
if(comp=='P'){
printf("\tThe computer chose paper. You lose.");
compScore++;
}
if(comp=='S'){
printf("\tThe computer chose scissors. You win!");
userScore++;
}
} else if(userChoice=='P'){
if(comp=='R'){
printf("\tThe computer chose rock. You win!");
userScore++;
}
if(comp=='P'){
printf("\tThe computer chose paper. You tied.");
tieScore++;
}
if(comp=='S'){
printf("\tThe computer chose scissors. You lose.");
compScore++;
}
}
if(userChoice=='S'){
if(comp=='R'){
printf("\tThe computer chose rock. You lose.");
compScore++;
}
if(comp=='P'){
printf("\tThe computer chose paper. You win!");
userScore++;
}
if(comp=='S'){
printf("\tThe computer chose scissors. You tied.");
tieScore++;
}
}
// add up of scores after each round
printf("\n\tScores: ");
if(userScore>0){
printf(" You-%d ", userScore);
}
if(compScore>0){
printf(" Computer-%d ", compScore);
}
if(tieScore>0){
printf("Ties-%d\n", tieScore);
}
}
//final add up of scores and totals
printf("\nThe game of %d matches is complete. The final scores are:\n", numGames);
printf("You: %d\n", userScore);
printf("Computer: %d\n", compScore);
printf("Ties: %d \n", tieScore);
return(0);
}
There is an extra case need to be added and below is the fixed code
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Complete the convert() method that casts the parameter from a double to an integer and returns the result.Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 code: public class LabProgram { public static int convert(double d){ /* Type your code here */ } public static void main(String[] args) { System.out.println(convert(19.9)); System.out.println(convert(3.1)); }}arrow_forwardCreate a Point classCreate a Point class as we did in the class. We'll use this to create Point objects that hold x,y coordinates of locations where we'll want to draw. Draw DotsWrite a drawDots(points) function that takes a list points as input and draws a dot on the drawing window for each Point. For example, you should be able to call your function as follows: >>> p = Point(10, 20) >>> q = Point(20, 30) >>> points = [p, q] >>> drawDots(points)arrow_forwardFor the 8 Java statements below, identify each of the following statements as legal or illegal, and whether legal or not, state whether it represents a "narrowing" or "widening" conversion, or neither. Don't forget to identify the last statement at the very bottom, Member m = new BoardMember();, as legal or illegal and widening or narrowing conversion.arrow_forward
- Chapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and computer choices…arrow_forwardFaceUp card game In this assignment we will implement a made-up card game we'll call FaceUp. When the game starts, you deal five cards face down. Your goal is to achieve as high a score as possible. Your score only includes cards that are face up. Red cards (hearts and diamonds) award positive points, while black cards (clubs and spades) award negative points. Cards 2-10 have points worth their face value. Cards Jack, Queen, and King have value 10, and Ace is 11. The game is played by flipping over cards, either from face-down to face-up or from face-up to face-down. As you play, you are told your total score (ie, total of the face-up cards) and the total score of the cards that are face down. The challenge is that you only get up to a fixed number of flips and then the game is over. Here is an example of the output from playing the game: FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 0 Face down total: -5 Number of flips left: 5 Pick a card to flip between 1…arrow_forwardComputer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forward
- Instructor note: This lab is part of the assignment for this chapter. This lab uses two Java files, LabProgram.java and SimpleCar.java. The SimpleCar class has been developed and provided to you already. You don't need to change anything in that class. Your job is to use the SimpleCar class to complete the specified tasks in the main() method of LabProgram.java Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations: Drives input number of miles forward Drives input number of miles in reverse Honks the horn Reports car status The SimpleCar class is found in the file SimpleCar.java. Ex: If the input is: 100 4 the output is: beep beep Car has driven: 96 milesarrow_forwardWhat would be the missing line of codes?arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY