EVPR Notes
EVPR Notes
Rock-Paper-Scissors
Scenario: A two-player or player-vs-computer game.
Pseudo-code:
1. Input:
o Player chooses rock, paper, or scissors.
o Computer randomly selects an op on (if single-player
mode).
2. Rules:
o Rock beats scissors, scissors beat paper, paper beats rock.
o Declare the winner based on the rules.
3. Repeat: Allow mul ple rounds and keep score.
Key Concepts in C:
Use rand() for computer's choice.
switch or if-else for game rules.
Loop to repeat rounds and maintain scores.
Name :- Y S R Ushendra
Registra on Number :- 2024040314
CODE IN WRITTEN FORMAT :-
#include <stdio.h>
int main() {
char playerChoice;
int computerChoice;
int choiceIndex = 0;
// Game loop
do {
choiceIndex++;
if (computerChoice == 0) {
prin ("rock\n");
} else if (computerChoice == 1) {
prin ("paper\n");
} else {
prin ("scissors\n");
}
// Determine the winner
playerScore++;
computerScore++;
} else {
rounds++;
char playAgain;
if (playAgain != 'y') {
break; // Exit the loop if player does not want to play again
} while (1);
// Final score
} else {
return 0;
This is where we built the rounds mechanism with the use of the looping
structure.
Then we made computer choose something from rock, paper & scissor but we
created a sequence for it which obviously player doesn’t know
And lastly displaying the computer’s choice.
Here, is where the declara on of the winner is established.
As the rules given in the case study the winner would be declared through that
method only.
And if a miss-clicks happen the registered program will automa cally give
player the chance to choose from the same op on that are valid.
And lastly there is the declara on of the rounds played and the winner of the
each round.
This is where we ask the player if they want to play more (round system).
And the answer should be in (y/n).
If player wishes to end the game (a er selec ng n), then the final result will be
declared and the overall winner of the game.
If the score of both the player and the computer is equal than it will be
declared as a e.
OUTPUT OF THE FOLLOWING CODE OF ROCK,PAPER & SCISSOR: