In: Computer Science
PROGRAMING in C RPSLS:
The program that we must implement must allow two players to
play in the same console (there will be only one program)
The program will initialize the information necessary to be able to
store the name of two players and their respective markers
throughout the game, to present
a result message at the end of the game.
1. When the program is ready for the game to start, it will ask
PLAYER1 enter your name.
2. It will then ask PLAYER2 to enter their name.
As long as the game is not over (that is, until one of the two
players arrives to 3 points) the program:
• Will ask PLAYER1 to place his bet (can be entered in the form of
numeric code, or in the form of a character string)
• Will ask PLAYER2 to place his bet (similarly)
• Evaluate both bets, and modify the markers of each of the two
players based on bets
• When either of the two players reaches the score of 3 points, it
will be over the game
3. Message will be displayed on the screen that says: "PLAYER NAME1 has won PLAYERNAME2: SCOREBOARD "if PLAYER1 has won, where SCORE will be the result of the game (for example 3-2).
Then it will say "PLAYERNAME2 has lost against PLAYER NAME1: MARKER "because then PLAYER2 will have lost, and MARKER will have the result reversed (for example 2-3). If he player who has won is PLAYER2, the messages will indicate the victory of the PLAYER2 and PLAYER1's defeat.
As soon as the above message is presented, the program will end
the program must NOT have any input parameters at the time of
making
the program call, and all the parameters you might need (names and
bets) will be entered by keyboard (upon presentation of a message
that clearly state what the user is expected to key in (such as,say
your NAME, enter your BET, etc.)
#include<stdio.h>
#include<conio.h>
void main()
{
char player1[10],player2[10];
int in1,in2;
printf("HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME\nWhat is player1's name?\n ");
scanf("%s",&player1);
printf("What is player2's name?\n ");
scanf("%s",&player2);
printf("%s and %s please follow the rules for the game\nPress 1 for stone\nPress 2 for paper\nPress 3 for scissors\n\n",player1,player2);
printf("Now let us start the game\n");
printf("%s is it STONE 1, PAPER 2 OR SCISSORS 3\n",player1);
scanf("%d",&in1);
printf("%s is it STONE 1, PAPER 2 OR SCISSORS 3\n",player2);
scanf("%d",&in2);
if ((in1==1 && in2==1) || (in1==2 && in2==2) || (in1==3 && in2==3))
printf("Neither %s nor %s won, it is a draw",player1,player2);
else if ((in1==1 && in2==3) || (in1==3 && in2==2) || (in1==1 && in2==3)|| (in1==2 && in2==1) || (in1==3 && in2==2) || (in1==1 && in2==3))
printf("Congrats %s! You won!!!!",player1);
else if ((in1==1 && in2==2) || (in1==3 && in2==1) || (in1==1 && in2==2)|| (in1==2 && in2==3))
printf("Congrats %s! You won!!!!",player2);
}
OUTPUT:
HELLO, WELCOME TO ROCK, PAPER, SCISSORS GAME
What is player1's name?
Alex
What is player2's name?
John
Alex and John please follow the rules for the game
Press 1 for stone
Press 2 for paper
Press 3 for scissors
Now let us start the game
Alex is it STONE 1, PAPER 2 OR SCISSORS 3
1
John is it STONE 1, PAPER 2 OR SCISSORS 3
2
Congrats John! You won!!!!