Rock Paper Scissors
Rock Paper Scissors
Satvik Alla
CONTENTS
About
Problem statement
Introduction
Design
Implementation
Coding
Output
Conclusion
C++ PROJECT 3
1. About
Rock Paper Scissor is a game played using the hands of 2 players. Using hand gestures, the
players then select one from Rock, Paper, or Scissors. The winner of the game is decided
according to the game rules. We tried to implement the game using C++ code where the user will
be one player and the computer will be the other player. The code is written so that the computer
asks the user to select one from Rock, Paper, or Scissors and then picks up a random choice from
Rock, Paper, or Scissors. The code then determines the winner and prints it on the screen. The
2. Problem Statement
- Purpose: This program simulates the popular game of Rock Paper Scissors.
programming concepts. The goal of this game is to implement a classic rock-paper-scissors game
between a user and a computer opponent. The aim is to provide the user with an interactive and
entertaining experience of the game. This code requires the user to input a choice of his own,
then the computer generates a random number, and then based on the game rules the winner
needs to be determined.
3. Introduction
- Game Description: Rock Paper Scissors is a hand game usually played between two people,
where each player simultaneously forms one of three shapes with an outstretched hand: rock,
paper, or scissors. The winner is determined by the rules: rock crushes scissors, scissors cut
- Motivation: The motivation for building this program includes practicing C++ programming
skills, understanding basic game logic, and implementing user input/output functionalities. Rock
C++ PROJECT 4
Paper Scissors is a hand gesture game played between 2 players and in the problem, we are
introducing the computer as the opponent and the user as the player. The player is promoted to
choose the choice of his own from Rock or Paper or Scissors and then the computer chooses one
from them using a random function and the winner is then determined and printed on the screen.
4. Design
The program has been designed using 2 user-defined functions 1). getComputer_choice and 2).
determineWinner. A library function main() is also used in the program. Apart from 2 user-
defined functions and a library function, this program used a “rand” function to generate a
random number.
a) getComputer_choice:
This function is used to generate a random number using ‘rand()’ method and maps it to one of
the choices among the rock paper or scissors. The ‘srand(time(0))’ call seeds the random
number generator with the current time to ensure different sequences on each run.
This function takes the choices of the player/user and computer as input and compares them with
each other to determine the winner. The parameters of the comparison are determined in the
function. Based on the parameters the functions return the result as a string: tie, player win or
computer win.
c) Main();
C++ PROJECT 5
The main() function is the entry point of the program. It prompts the user to enter their choice
and ensures valid input by converting it to the lower case and validating against the allowed
choices. The computer’s choice is then obtained, and the winner is determined and displayed.
5. Implementation
The code is a hand gesture game where two users play using their hands. Here we are
substituting one of the players with the computer and the other player is the user. Here
user needs to input the choice of his own to the computer from Rock, Paper, and Scissors.
Using the ‘rand()’ function the computer generates a random number in the
random_number = rand() % 3;’ has been used. The random number generated has been
reminders are in the range of 0-2 (including) and every value is assigned with Rock,
Paper or Scissor in the function and that value is returned as the ‘getComputer_choice’
in the below lines of code to determine the winner. The computer’s choice is compared to
the player’s value and then compared with each other in this function. Then the code
decides the winner with the greatest value. This function prints the winner on the screen
and prints ‘It’s a Tie’ if the choices of both the computer and the user are the same.
The ‘main()’ function is used to take inputs and print outputs in the program. The main
function takes input from the user as the user choice, if the desired input is not given by
the user the ‘main()’ function prints an error message to the user encouraging them to
choose between Rock, Paper, or Scissor. This also converts the user choice into lowercase
letters using ‘c = tolower(c);’ method to compare the user choice with the computer
C++ PROJECT 6
tolower(c);’ is much more important to convert the user choice into lowercase letters
6. Coding
#include <iostream>
#include <ctime>
string getComputerChoice() {
switch (randNum) {
case 0:
return "rock";
case 1:
return "paper";
case 2:
return "scissors";
if (playerChoice == computerChoice)
else
int main() {
string playerChoice;
c = tolower(c);
cout << "Invalid choice. Please enter rock, paper, or scissors: ";
c = tolower(c);
return 0;
7. Output
- Expected Output: The program will display the result of each round, including whether the user
wins, loses, or is a tie. It will also provide an option to quit the game.
8. Conclusion
C++ PROJECT 9
- Achievements: The program successfully implements the Rock Paper Scissors game in C++,
features like keeping track of scores, implementing a graphical user interface, or adding more