You are on page 1of 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