PROGRAM 2 Write an interactive program that plays the game o
Solution
Answer:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
do{
string playerOption;
int system;
cout << \"Are you ready to play Rock, paper, or scissors? \" << endl;
cout << \" \" << endl;
cin >> playerOption;
cout << \"Your entry: \" << playerOption << endl;
cout << \" \" << endl;
srand(time(NULL));
system = rand() % 10 + 1;
if (system <= 3)
{
cout << \"system entry: Rock\" << endl;
cout << \" \" << endl;
}
else if (system <= 6)
{
cout << \"system entry: Paper\" << endl;
cout << \" \" << endl;
}
else if (system >= 7)
{
cout << \"system entry: Scissors\" << endl;
cout << \" \" << endl;
}
if (playerOption == \"rock\" && system <= 3)
{
cout << \"It\'s a tie!\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"rock\" && system <= 6)
{
cout << \"You lose!\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"rock\" && system >= 7)
{
cout << \"You won the game\" << endl;
cout << \" \" << endl;
}
if (playerOption == \"paper\" && system <= 3)
{
cout << \"You won the game\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"paper\" && system <= 6)
{
cout << \"It is a tie\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"paper\" && system >= 7)
{
cout << \"You lost the game\" << endl;
cout << \" \" << endl;
}
if (playerOption == \"scissors\" && system <= 3)
{
cout << \"You lost the game\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"scissors\" && system <= 6)
{
cout << \"You won the game\" << endl;
cout << \" \" << endl;
}
else if (playerOption == \"scissors\" && system >= 7)
{
cout << \"It is a tie\" << endl;
cout << \" \" << endl;
}
} while (cin.get());
cin.get();
return 0;
}


