rock paper scissors game. plz check my program!!

I have to make a rock paper scissors game, have to use value returning function and not allowed to use void method. please check my program, why it's not working.

#include<iostream>
#include<cstdlib>
#include<string>
#include<ctime>
using namespace std;

int winner(int, int);

int main ()
{
char selection;
int rpsSel;
int compSel;

compSel = rand()%2+1;
srand((unsigned)time(0));

do
{
cout << endl;
cout <<"ROCK PAPER SCISSORS MENU\n";
cout <<"------------------------\n";
cout << "p) Play Game\n";
cout << "q) Quit\n";
cout << "Please enter your choice : \n";
cin >> selection;

if (selection == 'q')
{
cout << "You have chosen to quit the program. Thank you for using the program!" <<endl;
}
else if (selection == 'p')
{
cout << "Rock, Paper, or Scissors?\n";
cout << "1) Rock\n";
cout << "2) Paper\n";
cout << "3) Scissors\n";
cout << "Please enter your choice : \n";
cout << "\n";
cin >> rpsSel;
cin >> compSel;
cout << "You chose : " << rpsSel <<endl;
cout << "The computer chose : " << compSel <<endl;
cout <<endl;

winner(rpsSel,compSel);

cout <<endl;
}
else if (selection != 'p' || selection != 'q')
{
cout << "Invalid selection. Try again." <<endl;
}
}while(selection == 'q');

system ("PAUSE");
return 0;
}

int winner (int rpsSel, int compSel)
{
if (rpsSel == 1)
{
if (compSel = 1)
{
cout << "It's a TIE!" <<endl;
}
else if (compSel = 2)
{
cout << "You LOSE!"<<endl;
}
else if (compSel = 3)
{
cout << "You WIN!"<<endl;
}
}
else if (rpsSel == 2)
{
if (compSel = 1)
{
cout << "You WIN!"<<endl;
}
else if (compSel = 2)
{
cout << "It's a TIE!"<<endl;
}
else if (compSel = 3)
{
cout << "You LOSE!"<<endl;
}
}
else if (rpsSel == 3)
{
if (compSel = 1)
{
cout << "You LOSE!" <<endl;
}
else if (compSel = 2)
{
cout << "You WIN!"<<endl;
}
else if (compSel = 3)
{
cout << "It's a TIE!"<<endl;
}
}

}

Please use code tags next time; it makes it much easier to read (highlight your code and press the "<>" under Format).

 
compSel = rand()%2+1;


This will only give you 1 or 2, but for this you want 1, 2, or 3, so use %3 instead of %2.

1
2
cin >> rpsSel;
cin >> compSel;


Get rid of the second input. You're making the user overwrite the randomly generated computer choice.

 
while(selection == 'q');


This will only NOT end when the user chooses to exit. Use != instead of ==.
Your int winner(int, int); function is supposed to return an integer but it dosn't. If you need to return something just to please your teacher. You could return a string instead, such as return "You win!";You also have statements like this (compSel = 1) this should be an equality statement not an assignment statement.
Topic archived. No new replies allowed.