outcome of a game of Rock, Paper, Scissors. You do not need to build the actual game; your main() function does not need to be developed player1 and Player2 will each enter Rock, Paper or Scissors.
Standard rules of who won any given match apply: Rock beats
Scissors. Scissors beats Paper. Paper beats Rock. A Draw occurs if
both players enter the same shape
The requirements of the function are as follows:
The function accepts two char arrays as input
The function outputs a single char array
The char arrays passed to the function can contain any series of characters (i.e. it accepts any word)
The function's main role is to determine who won a game of Rock, Paper, Scissors
The output char array of the function can be 1 of 4 words:
“Player1"
This is the output if Player1 won the match
“Player2"
This is output if Player2 won the match
“Draw"
This is the output if both players entered the same shape
Invalid
#include<stdio.h>
char * game(char * p1, char *p2){
char * player1 = "Player1";
char *player2="Player2";
char * draw = "Draw";
if(p1=="Rock" && p2=="Scissors"){
return player1;
}
else if(p2=="Rock" && p1=="Scissors"){
return player2;
}
else if(p2=="Scissors" && p1=="Paper"){
return player2;
}
else if(p2=="Paper" && p1=="Scissors"){
return player1;
}
else if(p2=="Rock" && p1=="Paper"){
return player2;
}
else if(p2=="Paper" && p1=="Rock"){
return player1;
}
else if(p2=="Paper" && p1=="Paper"){
return draw;
}
else if(p2=="Rock" && p1=="Rock"){
return draw;
}
else if(p2=="Scissors" && p1=="Scissors"){
return draw;
}
}
int main(){
printf(game("Scissors", "Scissors"));
}
Comments
Leave a comment