I'm supposed to redesign this paper scissors rock game that first happened between 2 players, and for only one round. Yet, now I'm supposed to take for loops and ask them if they want to play against an A.I., or against just another player, or another player and an A.I.. Also, I am supposed to ask them how many rounds they want to play using the for loop. This is the jumble of mess I started, and I haven't been able to work around it so far.. A little bit of help to clear some things up in my code would be nice.
//4. Re-write the rock-paper-scissors program to first prompt the user for the number of rounds they would like to play.
//You only need to prompt the user for their name once. After all rounds are over, the program should display the win rate of both
//players and who was the total winner. Also prompt the user if they would like to play against a AI. If so the AI’s player name is
//CP and just chooses a random option.
//Example additional output:
//<player1name> won x out of y games.
//<player2name> won z out of y games.
//<playerx> is the champion!
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int ROCK = 1,
PAPER = 2,
SCISSORS = 3;
int numplayer;
int numround;
char player3;
string p1,
p2;
string ai = "CP";
string question;
int c1,
c2;
int c3;
cout << "How many rounds of Paper, Scissors, Rock would you like to play?\n";
cin >> numround;
cout << "How many players would you like to play with?\n";
cin >> numplayer;
cout << "Player 1, what is your name? ";
cin >> p1;
for (int i = 0; i < numround; i++)
{
if (numplayer == 1)
{
cout << p1 << ", please choose your weapon: \n"
<< "\t1) Rock\n"
<< "\t2) Paper\n"
<< "\t3) Scissors\n"
<< "Enter your choice: ";
cin >> c1;
srand(time(0));
int range = 3;
int min = 1;
int randNum = rand() % range + min;
c2 = randNum;
}
else if( c1 == c2 )
{
cout << p1 << " and " << ai << " tied!\n";
}
else if ((c1 == ROCK && c2 == PAPER ) ||
(c1 == PAPER && c2 == SCISSORS) ||
(c1 == SCISSORS && c2 == ROCK ))
{
cout << ai << " wins!\n";
}
else {
cout << p1 << " wins!\n";
}
}
if (numplayer == 2)
{
cout << "Would you like to play with A.I.?\n";
cin >> question;
}
if (question == "yes")
{
cout << "Player 2, please enter your name: ";
cin >> p2;
cout << p1 << ", please choose your weapon: \n"
<< "\t1) Rock\n"
<< "\t2) Paper\n"
<< "\t3) Scissors\n"
<< "Enter your choice: ";
cin >> c1;
system("cls");
cout << p2 << ", please choose your weapon: \n"
<< "\t1) Rock\n"
<< "\t2) Paper\n"
<< "\t3) Scissors\n"
<< "Enter your choice: ";
cin >> c2;
system("cls");
srand(time(0));
int range = 3;
int min = 1;
int randNum = rand() % range + min;
c3 = randNum;
if( c1 == c2 == c3 )
{
cout << p1 << " and" << p2 << " and" << ai << " tied!\n";
}
else if ( c1 == c2 && c2 != c3)
cout << p1 << " and" << p2 << " tied!\n" << "But" << ai << " loses!\n";
else if ( c1 != c2 && c2 == c3 )
cout << p2 << " and" << ai << " tied!\n" << "But" << p1 << " loses!\n";
else if ( c1 == c3 && c3 != c2 )
cout << p1 << " and" << ai << " tied!\n" << "But" << p2 << " loses1\n";
else if ((c1 == ROCK && c2 == PAPER && c3 == ROCK ) ||
(c1 == PAPER && c2 == SCISSORS && c3 == PAPER) ||
(c1 == SCISSORS && c2 == ROCK && c3 == SCISSORS ))
{
cout << p2 << " wins!\n";
}
else if ((c1 == ROCK && c2 == SCISSORS && c3 == SCISSORS ) ||
(c1 == PAPER && c2 == ROCK && c3 == ROCK) ||
(c1 == SCISSORS && c2 == PAPER && c3 == PAPER ))
{
cout << p1 << " wins!\n";
}
else if ((c1 == PAPER && c2 == PAPER && c3 == SCISSORS ) ||
(c1 == SCISSORS && c2 == SCISSORS && c3 == ROCK) ||
(c1 == ROCK && c2 == ROCK && c3 == PAPER ))
{
cout << ai << " wins!\n";
}
else if(question == "no")
{
cout << p1 << ", please choose your weapon: \n"
<< "\t1) Rock\n"
<< "\t2) Paper\n"
<< "\t3) Scissors\n"
<< "Enter your choice: ";
cin >> c1;
system("cls");
cout << p2 << ", please choose your weapon: \n"
<< "\t1) Rock\n"
<< "\t2) Paper\n"
<< "\t3) Scissors\n"
<< "Enter your choice: ";
cin >> c2;
system("cls");
if( c1 == c2 )
{
cout << p1 << " and " << p2 << " tied!\n";
}
else if ((c1 == ROCK && c2 == PAPER ) ||
(c1 == PAPER && c2 == SCISSORS) ||
(c1 == SCISSORS && c2 == ROCK ))
{
cout << p2 << " wins!\n";
}
else
cout << p1 << " wins!\n";
}
}
system("PAUSE>N UL");
return 0;
}