1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
# include <ctime>
# include <cstdlib>
using namespace std;
int computerChoice()
{
srand(time(0));
int compChoice = rand()2;
return compChoice;
}
int main()
{
int playerChoice = 0;
cout << "Hello, and welcome to Rock, Paper, Scissors!\n\nRules of the game are: \n\n1) Rock beats scissors\n2) Scissors beats paper\n3) Paper beats rock.\n";
cout <<"\nPlease make your choice: \n\nPick 0 for rock, 1 for paper and 2 for scissors (Press -1 to exit)." << endl;
cin >> playerChoice;
int compNumber = computerChoice();
switch(compNumber)
{
case 0:
if (playerChoice == 0)
{
cout << "\nYou picked rock, and the computer picked rock. The game is tied!\n";
break;
}
if (playerChoice == 1)
{
cout << "\nYou picked paper, and the computer picked rock. You win!\n";
break;
}
if (playerChoice == 2)
{
cout << "\nYou picked scissors, and the computer picked rock. You lose!\n";
break;
}
case 1:
if (playerChoice == 0)
{
cout << "\nYou picked rock, and the computer picked paper. You lose!\n";
break;
}
if (playerChoice == 1)
{
cout << "\nYou picked paper, and the computer picked paper. The game is tied!\n";
break;
}
if (playerChoice == 2)
{
cout << "\nYou picked scissors, and the computer picked paper. You win!\n";
break;
}
case 2:
if (playerChoice == 0)
{
cout << "\nYou picked rock, and the computer picked scissors. You win!\n";
break;
}
if (playerChoice == 1)
{
cout << "\nYou picked paper, and the computer picked scissors. You lose!\n";
break;
}
if (playerChoice == 2)
{
cout << "\nYou picked scissors, and the computer picked scissors. The game is tied!\n";
break;
}
default:
cout << "Invalid number, try again" << endl;
}
return 0;
}
|