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

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

ID: 3803163 • Letter: P

Question

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 ",Cscore,Pscore);
}
else if(Cscore < Pscore ){
printf("Player wins %d to %d ",Pscore,Cscore);
}
else if(Cscore ==Pscore ){
printf("No winner it is a draw! ");
}

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, "
" then rock wins. (Rock smashes scissors.) "
"* If one player chooses scissors and the other player chooses paper, "
" then scissor wins. (Scissor cuts paper.) "
"* If one player chooses paper and the other player chooses rock, "
" then paper wins. (Paper covers rock.) "
"* If both players make the same choice, "
" the game is a tie.(The game must be played again to determine the winner.) " );
}

int determine_winner(int choice, int computer)
{
  
    if(choice==1){
if(computer==1){
printf("Draw ");
}
if(computer==2){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
if(computer==3){
printf("Player Wins ");
Pscore = Pscore + 1;
}
}
else if(choice==2){
if(computer==2){
printf("Draw ");
}
if(computer==3){
printf("Player Wins! ");
Pscore = Pscore + 1;
}
if(computer==1){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
}
else if(choice==3){
if(computer==3){
printf("Draw ");
}
if(computer==2){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
if(computer==1){
printf("Player Wins! ");
Pscore = Pscore + 1;

}
}
else{
printf("Wrong Answer ");
}

}
  
}
  
  

Explanation / Answer

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 ",Cscore,Pscore);
}
else if(Cscore < Pscore ){
printf("Player wins %d to %d ",Pscore,Cscore);
}
else if(Cscore ==Pscore ){
printf("No winner it is a draw! ");
}


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, "
" then rock wins. (Rock smashes scissors.) "
"* If one player chooses scissors and the other player chooses paper, "
" then scissor wins. (Scissor cuts paper.) "
"* If one player chooses paper and the other player chooses rock, "
" then paper wins. (Paper covers rock.) "
"* If both players make the same choice, "
" the game is a tie.(The game must be played again to determine the winner.) " );
}

void determine_winner(int choice, int computer)
{

if(choice==1){
if(computer==1){
printf("Draw ");
}
if(computer==2){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
if(computer==3){
printf("Player Wins ");
Pscore = Pscore + 1;
}
}
else if(choice==2){
if(computer==2){
printf("Draw ");
}
if(computer==3){
printf("Player Wins! ");
Pscore = Pscore + 1;
}
if(computer==1){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
}
else if(choice==3){
if(computer==3){
printf("Draw ");
}
if(computer==2){
printf("Computer Wins! ");
Cscore= Cscore + 1;
}
if(computer==1){
printf("Player Wins! ");
Pscore = Pscore + 1;
}
}
else{
printf("Wrong Answer ");
}

}

FEEL FREE TO COMMENT BELOW