Thanks for replying. I *think* I understood what you meant. In any case, I've started from scratch after numerous attempts with my initial code. So now I have the user input function working and hopefully the computer function too.
I'm having trouble with the output however, which is the void function printResults. How do I pass the answers gathered from the user and computer inputs through to the void function and then call it? I couldn't figure out how to get the returned values from the first two functions...
Also, do I need the #include <algorithm>, #include <cctype> statements?
New code:
Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;
char compChoice(int c)
{
char random = 0;
random = rand() % 3;
if (random = 0)
random = 'R';
if (random = 1)
random = 'P';
if (random = 2)
random = 'S';
return random;
}
//*****************************************************************
char humChoice(string q, char a)
{
while (a != 'Q')
{
cout << q;
cin >> a;
a = toupper(a);
if (a == 'R') break;
if (a == 'P') break;
if (a == 'S') break;
}
return a;
}
//*****************************************************************
void printResults(string result1, string result2, char a)
{
cout << result1 << result2 << a << endl;
}
//*****************************************************************
int main()
{
// initialize the computer's random number generator
srand(time(0));
// declare variables
char R = 0;
char P = 0;
char S = 0;
char Q = 0;
char a = 0;
// start loop
while (true)
{
// determine computer's choice
char comp = compChoice(P);
// prompt for, and read, the human's choice
char user = humChoice("Choose: [Rock,Paper,Scissors,Quit]: ", 'R'
);
// if human wants to quit, break out of loop
if (user = 'Q') break;
// end loop
}
// print results
printResults("Computer: ", ", Human: ", 'a');
// end program
return 0;
} // main