Do-while loop wont work!

using namespace std;

int main()


char a, b, choice;
int player1_wins = 0;
int player1_loses = 0;
int player2_wins = 0;
int player2_loses = 0;

cout << "Welcome to Rock, Paper, Scissors!\n" << endl;

cout << "Please enter r/p/s for your choice.\n" << endl;


cout << "Player 1:";

cin >> a;

cout<<"\nPlayer 2:";


if ((a=='r' || a=='R') && (b=='s' || b=='S'))

cout<< "\nPlayer 1 wins, Rock breaks Scissors!\n" << endl;

else if ((a=='r' || a=='R') && (b=='p' || b=='P'))

cout<<"\nPlayer 2 wins, Paper covers rock!\n" << endl;

else if ((a=='r' || a=='R') && (b=='r' || b=='R'))

cout<<"\nIt's a tie!\n" << endl;

else if ((a=='p' || a=='P') && (b=='s' || b=='S'))

cout<<"\nPlayer 2 wins, Scissors cut paper!\n " << endl;

else if ((a=='p' || a=='P') && (b=='r' || b=='R'))

cout<<"\nPlayer 1 wins, Paper covers rock!\n " << endl;

else if ((a=='P' || a=='P') && (b=='p' || b=='P'))

cout<<"\nIt's a tie!\n" << endl;

else if ((a=='s' || a=='S') && (b=='P' || b=='p'))

cout<<"\nPlayer 1 wins, Scissors cut paper!\n" << endl;

else if ((a=='s' || a=='S') && (b=='R' || b=='r'))

cout<<"\nPlayer 2 wins, Rock breaks scissors!\n" << endl;

else if ((a=='s' || a=='S') && (b=='s' || b=='S'))

cout<<"\nIt's a tie!\n" << endl;

if( player_one_wins ) ++player1_wins;

cout << "Play again? (y/n): ";
cin >> choice;


while (choice == 'y');

Last edited on
Could you elaborate on what doesn't work?
The program runs and all, but when the user enters "y" for choice, the program closes. And it doesn't repeat the program.
Move the return( 0 ); outside of the do/while loop. You are telling it to end the program and to send 0 to the operating system. Also please put code tags around your code.
[code]//some code[/code]
Thank youu so much!! I was stuck on this for quite a while now.
i also need to to add up the scores. My teacher said it has to be like this.
Could you help me with that?

Welcome to Rock Paper Scissors!
Please enter r/p/s for your choice.
Player 1: r
Player 2: p
Player 2 wins, Paper covers Rock!
Player 1: 0 win(s), 1 loss(es)
Player 2: 1 win(s), 0 loss(es)
Play again? (y/n): y
create 4 variable then to keep track of wins/loses for each player.

Then at the end of your loop add one to winners wins and one to the losers loses. Then output the wins/loses each time before asking them to play again.
Could you tell me how to do that?
Like what variable would i use and what type?
(I'm sorry i dont know shit about what i'm doing)
int player1_wins = 0;
int player1_loses = 0;
int player2_wins = 0;
int player2_loses = 0;

then to increment

I just did that but it says the increment is an undeclared identifier?
I think i'll be needing step by step instructions. I really suck at this :p
Last edited on
dont use playerx_wins/loses replace that with who won and who lost each round. You will need if statements

if( player_one_wins ) ++player1_wins;
like that.
is that good?
You weren't supposed to copy/paste you were supposed to fill in the blanks...

Look at your code. You have if statements telling which player wins.

Say for example the first if statement is player 1 wins because he has rock and they have scissor. Then you will add one to player one wins and one to player two losses.

*You will need to use curly braces so you can put more than one statement in each if statement.
Last edited on
Topic archived. No new replies allowed.