0% found this document useful (0 votes)
16 views

Itc Lab Project

This C++ code implements a rock-paper-scissors game that allows a user to play against a computer opponent. The user can choose between rock, paper, scissors or quit, and the computer randomly selects its move. After both players make their selection, the code determines if it is a tie, if the user wins, or if the computer wins based on the traditional rock-paper-scissors rules. The game continues looping until the user chooses to quit.

Uploaded by

manahilnasir67
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Itc Lab Project

This C++ code implements a rock-paper-scissors game that allows a user to play against a computer opponent. The user can choose between rock, paper, scissors or quit, and the computer randomly selects its move. After both players make their selection, the code determines if it is a tie, if the user wins, or if the computer wins based on the traditional rock-paper-scissors rules. The game continues looping until the user chooses to quit.

Uploaded by

manahilnasir67
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


int main()
{
cout << "Welcome to Rock-Paper-Scissors Game" << endl;
int userChoice, computerChoice;
while (true)
{
cout << "Choose your move (1 for Rock, 2 for Paper, 3 for Scissors, 0 to
Quit): ";
int userChoice;
cin >> userChoice;

if (userChoice == 0)
{
cout << "The game ended. Thank you for playing." << endl;
break;
}

switch (userChoice)
{
case 1:
cout << "You entered: Rock" << endl;
break;
case 2:
cout << "You entered: Paper" << endl;
break;
case 3:
cout << "You entered: Scissors" << endl;
break;
default:
cout << "Invalid Input. Please enter a number between 0 and 3" << endl;
continue;
}

computerChoice = rand() % 3 + 1;
cout << "Computer choose: " << computerChoice << endl;

switch (computerChoice)
{
case 1:
cout << "Computer entered: Rock" << endl;
break;
case 2:
cout << "Computer entered: Paper" << endl;
break;
case 3:
cout << "Computer entered: Scissors" << endl;
break;
}
if ((userChoice == 1 && computerChoice == 2) ||
(userChoice == 2 && computerChoice == 3) ||
(userChoice == 3 && computerChoice == 1))
cout << "Computer wins" << endl;
else if (userChoice == computerChoice)
cout << "It's a tie" << endl;
else
cout << "You win" << endl;
}
return 0;
}

You might also like