please help me fix this. I'm getting it all mixed up in user defined functions.
here's the question.
This week we'll write a C program that lets the user play the game of Rock, Paper, Scissors against the computer. Your program will call a user-defined function named display_rules that displays the rules of the game. It then proceeds to play the game. To determine the winner, your program will call another user- defined function called determine_winner that takes two integer arguments (the user’s game choice and the computer’s game choice) and displays a message indicating the winner. here's what i have so far...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// function prototypes
void display_rules(void);
int determine_winner(int);
/// --------------------------------------------------------------------
/// Main entry-point for this application.
///
/// @return Exit-code for the process -0 for success, else an error
code.
///
--------------------------------------------------------------------
int main()
{
int Pscore =0; //initialize variable to keep score for user
wins
int Cscore =0; //initialize variable to keep score for computer
wins
int choice; //definite variable for user choice
srand(time(0)); // use current time as seed for random
generator
int computer=rand()%3+1; //get a new random integer
int i=0; //initialize variable to keep count of plays
while(i<5){
printf("Enter your choice:");
scanf("%d",&choice);
i++;
if(Cscore > Pscore ){
printf("Computer wins %d to %d\n",Cscore,Pscore);
}
else if(Cscore < Pscore ){
printf("Player wins %d to %d\n",Pscore,Cscore);
}
else if(Cscore ==Pscore ){
printf("No winner it is a draw!\n");
}
return 0;
}
///
----------------------------------------------------------------------------
/// Display a brief info message describing this program.
///
----------------------------------------------------------------------------
void display_rules(void)
{
printf( "* If one player chooses rock and the other player chooses
scissors,\n"
" then rock wins. (Rock smashes scissors.)\n"
"* If one player chooses scissors and the other player chooses
paper,\n"
" then scissor wins. (Scissor cuts paper.)\n"
"* If one player chooses paper and the other player chooses
rock,\n"
" then paper wins. (Paper covers rock.)\n"
"* If both players make the same choice,\n"
" the game is a tie.(The game must be played again to determine the
winner.)\n" );
}
int determine_winner(int choice, int computer)
{
if(choice==1){
if(computer==1){
printf("Draw\n");
}
if(computer==2){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
if(computer==3){
printf("Player Wins\n");
Pscore = Pscore + 1;
}
}
else if(choice==2){
if(computer==2){
printf("Draw\n");
}
if(computer==3){
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
if(computer==1){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
}
else if(choice==3){
if(computer==3){
printf("Draw\n");
}
if(computer==2){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
if(computer==1){
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
}
else{
printf("Wrong Answer\n");
}
}
}
CHECK THE BELOW CODE, IT WILL WORK NOW. I HAVE CORRECTED ALL THE SYNTAX ERRORS. CHEERS!
PLEASE RATE IF YOU CAN!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// function prototypes
void display_rules(void);
void determine_winner(int, int);
//GLOBAL VARIABLES
int Pscore =0; //initialize variable to keep score for user
wins
int Cscore =0; //initialize variable to keep score for computer
wins
///
--------------------------------------------------------------------
/// Main entry-point for this application.
///
/// @return Exit-code for the process -0 for success, else an error
code.
///
--------------------------------------------------------------------
int main()
{
int choice; //definite variable for user choice
srand(time(0)); // use current time as seed for random
generator
int computer=rand()%3+1; //get a new random integer
int i=0; //initialize variable to keep count of plays
display_rules(); //calling the rules function
while(i<5){
printf("Enter your choice:");
scanf("%d",&choice);
i++;
determine_winner(choice, computer);//call to determine_winner
function to determine winner
}
if(Cscore > Pscore ){
printf("Computer wins %d to %d\n",Cscore,Pscore);
}
else if(Cscore < Pscore ){
printf("Player wins %d to %d\n",Pscore,Cscore);
}
else if(Cscore ==Pscore ){
printf("No winner it is a draw!\n");
}
return 0;
}
///
----------------------------------------------------------------------------
/// Display a brief info message describing this program.
///
----------------------------------------------------------------------------
void display_rules(void)
{
printf( "* If one player chooses rock and the other player chooses
scissors,\n"
" then rock wins. (Rock smashes scissors.)\n"
"* If one player chooses scissors and the other player chooses
paper,\n"
" then scissor wins. (Scissor cuts paper.)\n"
"* If one player chooses paper and the other player chooses
rock,\n"
" then paper wins. (Paper covers rock.)\n"
"* If both players make the same choice,\n"
" the game is a tie.(The game must be played again to determine the
winner.)\n" );
}
void determine_winner(int choice, int computer)
{
if(choice==1){
if(computer==1){
printf("Draw\n");
}
if(computer==2){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
if(computer==3){
printf("Player Wins\n");
Pscore = Pscore + 1;
}
}
else if(choice==2){
if(computer==2){
printf("Draw\n");
}
if(computer==3){
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
if(computer==1){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
}
else if(choice==3){
if(computer==3){
printf("Draw\n");
}
if(computer==2){
printf("Computer Wins!\n");
Cscore= Cscore + 1;
}
if(computer==1){
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
}
else{
printf("Wrong Answer\n");
}
}
FEEL FREE TO COMMENT BELOW
please help me fix this. I'm getting it all mixed up in user defined functions. here's...
IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....
Python please. I have a working one that doesn't keep track of w/l ratio, it may be helpful to see how others did the entire program and inserted that module. Write a modular program that let the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random number in the range of 1 thru 3 is generated but do not display the computer choice immediately. Number 1...
(Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...
(c++ only)Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. If the...
(C++) Hey guys we just went over loops and it got me
confused, it has me scrathcing my head for the past two days. I
would appreciate any help you guys have to offer. Few places I have
a hard time is get input and determine winner(cummulative
part).
Write a program that lets the user play the Rock, Paper,
Scissors game against the computer. The computer first chooses
randomly between rock, paper and scissors, but does not display its
choice....
Python Language: Please see program listed below of a game called: Rock, Paper, Scissors. Please add an exception, for example if the user inputs something else other than rock, paper or scissors, the exception will print message: "Enter only rock, paper, or scissors". Also add option to keep playing the game, for example: print: "Would you like to play again? Enter Y or N". If the user says Y, the game will repeat, if N, the game will end and...
In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play the game of Rock, Paper, Scissors against the computer.Your program should have the following: •Make the name of the project RockPaperScissors•Write a method that generates a random number in the range of 1 through 3. The randomly generated number will determine if the computer chooses rock, paper, or scissors. If the number is 1, then the computer has chosen rock. If the number is...
In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....
Use Dev C++ for program and include all of the following. Im
lost.
Make sure the user enters a letter of R, P, or S and the
computer generates a number between 0-2 and changes that number to
a letter of R, P or S, using a switch. Make sure the user knows why
he/she has won or lost – print a message like “Paper covers Rock”
or “Scissors cuts Paper”.
Ask the user how many times he/she wants to...
JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...