//The do-while loop repeats the program until there is a winner
do
{
// Assigning variables and introduction to the game
srand ((unsigned)time(0));
compchoice = (rand()%2)+1;
cout << "Welcome to Rock, Paper, Scissors! Let's Play!\n\n";
cout << "Type 1 for rock, 2 for paper, or 3 for scissors\n\n";
cin >> choice;
// If and else if statements if #1 is chosen for Rock
if (choice == 1)
{
if (compchoice == 1)
cout << "The computer also chose rock, tie Game, try again!\n\n";
else if (compchoice == 2)
cout << "The computer chose paper and paper covers rock! You Lost! )-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and rock smashes scissors! You won! (-:\n\n";
}
// If and else if statements if #2 is chosen for Paper
if (choice == 2)
{
if (compchoice == 2)
cout << "The computer also chose paper, tie Game, try again...\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and paper covers rock! You won! (-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and scissors cuts paper! You lost! )-:\n\n";
}
// If and else if statements if #3 is chosen for Scissors
if (choice == 3)
{
if (compchoice == 3)
cout << "The computer also chose scissors, it's a tie, try again!\n\n …
else if (compchoice == 2)
cout << "The computer chose paper and scissors cuts paper! You won! (-:\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and rock smashes scissors! You Lost! )-:\n\n";
}
//The do-while loop repeats the program until there is a winner
} while(choice == compchoice);
return 0;
}[code]int main()
{
int choice, compchoice;
//The do-while loop repeats the program until there is a winner
do
{
// Assigning variables and introduction to the game
srand ((unsigned)time(0));
compchoice = (rand()%2)+1;
cout << "Welcome to Rock, Paper, Scissors! Let's Play!\n\n";
cout << "Type 1 for rock, 2 for paper, or 3 for scissors\n\n";
cin >> choice;
// If and else if statements if #1 is chosen for Rock
if (choice == 1)
{
if (compchoice == 1)
cout << "The computer also chose rock, tie Game, try again!\n\n";
else if (compchoice == 2)
cout << "The computer chose paper and paper covers rock! You Lost! )-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and rock smashes scissors! You won! (-:\n\n";
}
// If and else if statements if #2 is chosen for Paper
if (choice == 2)
{
if (compchoice == 2)
cout << "The computer also chose paper, tie Game, try again...\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and paper covers rock! You won! (-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and scissors cuts paper! You lost! )-:\n\n";
}
// If and else if statements if #3 is chosen for Scissors
if (choice == 3)
{
if (compchoice == 3)
cout << "The computer also chose scissors, it's a tie, try again!\n\n …
else if (compchoice == 2)
cout << "The computer chose paper and scissors cuts paper! You won! (-:\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and rock smashes scissors! You Lost! )-:\n\n";
}
//The do-while loop repeats the program until there is a winner