Programming project
Using c++ Language
Rock paper scissor
A Game against computer
By:
Momen Nazar Salim
Musa Thamer muhammed
Hadeel Amer Salih
Yassmin Haider Abid Al-ilah
Wael Ahmed Saady
Malak Khalid Nassif
Noor Al-huda Ali Noori
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{ srand(time(NULL));
int user = 0;
Int computer = 0;
cout << "Stone Paper Scissor Game" << endl;
cout << "1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissor" << endl;
cin >> user;
if(user == 1)
{cout << "You choose Rock" << endl; }
else if(user == 2)
{cout << "You choose Paper" << endl; }
else
{cout << "You choose Scissor" << endl; }
computer = rand()%3+1;
if(computer == 1)
{cout << "Computer chooses Rock" << endl;
else if(computer == 2)
{ cout << "Computer chooses Paper"<< endl; }
else{ cout << "Computer chooses Scissor" << endl; }
// match
if(user == computer)
{ cout << "Match Tie" << endl; }
// user --> Rock
else if(user == 1)
{ if(computer == 2)
{ cout << "You lose!" << endl; }
if(computer == 3)
{ cout << "You win!" << endl; } }
// user --> Paper
else if(user == 2)
{ if(computer == 1)
{ cout << "You win!" << endl; }
if(computer == 3)
{ cout << "You lose!" << endl; } }
// user --> Scissor else if(user == 3)
{ if(computer == 1)
{ cout << "You lose!" << endl; }
if(computer == 2){ cout << "You win!" << endl; } } return 0;}
The random results:
• Rock Paper Scissor Game
• 1)Rock
• 2) Paper
• 3) Scissor
• 1
• You choose Rock
• Computer chooses Scissor
• You win!
Another result:
• Rock Paper Scissor Game
• 1)Rock
• 2) Paper
• 3) Scissor
• 2
• You choose Paper
• Computer chooses Rock
• You win!
Another result:
• Rock Paper Scissor Game
• 1) Rock
• 2) Paper
• 3) Scissor
• 3
• You choose Scissor
• Computer chooses Rock
• You lose!
A discussion about this program:
How it woks:
• It uses c++ language to create a simple game (rock paper scissor)
And with a simple codes such as (if,else,cout,cin,Etc...).
• The program focuses on using loops wich in this case its a loop inside
another loop to make a good use out of (if,else).
• After we run the program we can write 1 or 2 or 3.
• The computer will choose a random number by using (rand) function.
• If you choose rock and the computer chooses paper the program will
print you lose and if its the opposite you win.
• If you choose scissor and the computer chooses paper the program
will print you win and if its the opposite you lose.
• If you choose rock and the computer chooses scissor the program will
print you win and if its the opposite you lose.