Question

please help me fix this. I'm getting it all mixed up in user defined functions. here's...

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");
}

}
  
}
  
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
please help me fix this. I'm getting it all mixed up in user defined functions. here's...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    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....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (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...

  • Python please. I have a working one that doesn't keep track of w/l ratio, it may...

    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...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (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....

  • In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play...

    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...

    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...

    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 pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT