I'm not sure how far I have left to go with my coding, but after I enter my play then I want the computer to play, it just repeats its play over and over until I control c to get out.
#include <iostream>
using namespace std;
// Leave the following line it. It's needed to make the compiler happy.
char cPlayRPS ();
// Add comment here re overall purpose of the program.
int main () {
// Declare variables to store the user's and the computer's play.
char userPlay;
int wins;
int losses;
int draws;
char cPlay;
// Also, declare and initialize variables to save the number of wins, losses, and draws.
// Prompt the user to make a play, and input it.
cout << "You Play (P for Paper, R for Rocks, S for Scissors or Q for Quit): ";
cin >> userPlay;
cout << "Computer Play: ";
cout << endl;
// Set up a loop to play a round, checking that user entered a valid choice.
while(userPlay != 'Q' && userPlay != 'q')
{
cout << "Computer Play: ";
cPlay = cPlayRPS();
cout << cPlay << endl;
if(userPlay== 'R' && cPlay=='P')
{
cout << "You win: Paper covers Rock";
wins=wins+1;
}
else if(userPlay=='R' && cPlay=='S')
{
cout << "You win: Rock crushes Scissors";
wins=wins+1;
}
else if(userPlay=='R' && cPlay=='R')
{
cout << "Draw";
draws=draws +1;
}
else if(userPlay =='P' && cPlay =='R')
{
cout << "You win: Paper covers Rock";
wins=wins+1;
}
else if(userPlay =='P' && cPlay=='S')
{
cout << "You lose: Scissors cuts Paper";
losses=losses+1;
}
else if(userPlay=='P' && cPlay=='P')
{
cout << "Draw";
draws=draws+1;
}
else if(userPlay=='S' && cPlay=='P')
{
cout << "You win: Scissors cuts Paper";
wins=wins+1;
}
else if(userPlay=='S' && cPlay=='R')
{
cout << "You lose: Rock crushes Scissors";
losses=losses+1;
}
else if(userPlay=='S' && cPlay=='S')
{
cout << "Draw";
draws=draws+1;
}
}
cout << "Results: " << wins << losses << draws << endl;
cout << "All done. Thanks for playing.";
return 0;
}
char cPlayRPS () {
srand( time( NULL));
switch ( rand() % 3 ) {
case 0: return 'R';
case 1: return 'P';
case 2: return 'S';
}
}