#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
usingnamespace std;
int getUserChoose (int);
int getCompChose (int);
void WhoisWinner(int,int);
int main ()
{
int comp,user;
char answer;
cout << "Welcome to the program of Rock, Paper, Scissors" << endl;
cout << "The computer is ready to play the game" << endl;
cout << "Are you ready to play the game" << endl;
cout << "Y for yes and N for no " << endl;
cin >> answer;
while (answer == 'y' || answer == 'Y')
{
getUserChoose(user);
getCompChose(comp);
WhoisWinner(user,comp);
}
}
int getUserChoose (int answer)
{
char answerfromuser;
int trannum;
cout << "R = Rock; P = Paper; S = Scissors" << endl;
cin >> answerfromuser;
if (answerfromuser == 'R' || answerfromuser == 'r')
{
cout << "You have choose Rock " << endl;
trannum = 1;
}
elseif (answerfromuser == 'P' || answerfromuser == 'p')
{
cout << "You have choose Paper " << endl;
trannum = 2;
cout << trannum << endl;
}
elseif (answerfromuser == 'S' || answerfromuser == 's')
{
cout << "You have choose Scissors " << endl;
trannum = 3;
}
cout << trannum << "TN" << endl;
return trannum;
}
int getCompChose (int num)
{
srand( (unsignedint) time(NULL) );
num = (1 + rand() % 3);
cout << num << "RM" << endl;
return num;
}
void WhoisWinner(int pervuser,int pervcomp)
{
cout << pervuser << "U" << endl;
cout << pervcomp << "C" << endl;
/*
if (pervuser == 1 && pervcomp == 1)
{
cout <<"Nice Try" << endl;
cout <<"It a tie" << endl;
if (pervcomp == 2)
{
cout << "Computer win" <<endl;
}
else
{
cout <<"You win!" << endl;
}
}
else if (pervuser == 2)
{
if (pervcomp == 1)
{
cout <<"You win!" << endl;
}
else if (pervcomp == 2)
{
cout <<"Nice Try" << endl;
cout <<"It a tie" << endl;
}
else
{
cout <<"Computer win!" << endl;
}
}
else if (pervuser == 3)
{
if (pervcomp == 1)
{
cout <<"Computer win!" << endl;
}
else if (pervcomp == 2)
{
cout <<"You win! " << endl;
}
else
{
cout <<"Nice Try" << endl;
cout <<"It a tie" << endl;
}
}
*/
}
here is the output
Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C
You're calling the functions, but you're not storing the value they return.
1 2
getUserChoose(user);
getCompChose(comp);
Did you mean to do something like this? I don't see that you need to send any parameters to these functions - you just want to get their choice and return that value to main?
1 2
user = getUserChoose();
comp = getCompChose();
Edit: You only need to call srand once - not every time you call the computer choice function.