hello everybody. I am trying to write a game of rock paper scissors where the user plays against the computer. The computer picks a random number and the user makes his/her own selection. then the selections are compaired and the winner is selected.
I need to write the following in functions:
get user choice
get computer choice
i was able to get the winner in a function already.
the program works as it stands now but i have no idea how to put the user and computer choice in a function. here is my code
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void winner(int selection, int compSelection);
int main()
{
srand((unsigned)time(0));
int compSel = (rand()%2)+1;
int userSel;
cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
cout << " so lets begin. You are playing against the computer. Type 0 for";
cout << " rock, 1 for paper, and 2 for scissors\n";
cin >> userSel;
cout << "Computer Selects " << compSel << endl;
winner(userSel, compSel);
system("pause");
return 0;
}
*/
// ************************************************************************
// Winner
//
// task: Selects the winner
// data in: user choice and computer choice
// data out: Winner
//
// ***********************************************************************
void winner (int selection, int compSelection)
{
if (selection == 0)
{
if (compSelection == 0)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 1)
cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
else if (compSelection == 2)
cout << "Rock beats scissors! You win!\n\n\n\n";
}
else if (selection == 1)
{
if (compSelection == 0)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 1)
cout << "Paper beats rock! You win!\n\n\n\n";
else if (compSelection == 2)
cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
}
else if (selection == 2)
{
if (compSelection == 0)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 1)
cout << "Scissors beat paper! You win!\n\n\n\n";
else if (compSelection == 2)
cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
}
}
any suggestions?