Member Avatar for rp45

Hello,
I just joined this web site and i'm new to programming and i'm stuck on this program, can't seem to finish it, after couple of days of trying to figure this program out, i realize i need help.
The program is pretty much done i just don't know where to put the default for player one. I have it for player two, but not for one. Greatly appreciated if someone could help.
Thank you.

#include <iostream>
using namespace std;
                        
int main()
{
        char playerOne;
                char playerTwo;
                
                //Display player's choices
                cout << "Welcome to the rock-paper-scissors game.\n" ;
                cout << "Player 1 please enter your move: ('R' for rock,";
                cout << "'P' for paper, and 'S' for scissors)" << endl;
                cin >> playerOne;
                cout << "Welcome to the rock-paper-scissors game.\n" ;
                cout << "Player 2 please enter your move: ('R' for rock,";
                cout << "'P' for paper, and 'S' for scissors)" << endl;
                cin >> playerTwo;
                        
                        
                // Using the switch statement and switch statement
                if(playerOne == 'S' || playerOne == 's'){                                            
                
                        switch(playerTwo){
                        case 's':
                        case 'S': cout << "Tie with Scissors!" << endl;
                        break;
                        case 'r':
                        case 'R': cout << "Player 2 Wins: Rock breaks Scissors!" << endl;
                        break;
                        case 'p':
                        case 'P': cout << "Player 1 wins: Scissors cut Paper!!" << endl;
                        break;
                        }
                }
                else if (playerOne == 'R' || playerOne == 'r'){
                switch(playerTwo){
                        case 'r': 
                        case 'R': cout << "Tie with Rock!" << endl;
                        break;
                        case 'p':
                        case 'P': cout << "Player 2 Wins: Paper covers Rock!" << endl;
                        break;
                        case 's':
                        case 'S': cout << "Player 1 wins: Rock breaks Scissors!" << endl;
                        break;
                        }
                }
                   else
                {
                        switch(playerTwo){
                        case 'p':
                        case 'P': cout << "Tie with Paper!" << endl;
                        break;   
                        case 's':
                        case 'S': cout << "Player 2 Wins: Scissors cut Paper!" << endl;
                        break;   
                        case 'r':
                        case 'R': cout << "Player 1 wins: Paper covers Rock!!" << endl;
                        break;
                        default: cout << "player 2 has entered an invalid move." << endl;
                        break;
                        }
                        
                }
                return 0;
        }

Recommended Answers

All 3 Replies

Hello,
I just joined this web site and i'm new to programming and i'm stuck on this program, can't seem to finish it, after couple of days of trying to figure this program out, i realize i need help.
The program is pretty much done i just don't know where to put the default for player one. I have it for player two, but not for one. Greatly appreciated if someone could help.
Thank you.

defualt generally goes within the switch for player 1. Please be more explicit if that doesn't help. Remember, you understand the program and what you want to do, we don't unless you explain fully what the problem is.

Member Avatar for rp45

WaltP than you for the response. I placed the default for player one at the beginning of the last "else", just before i start the last switch for player two.
It seems to work fine, except i'm running to a new problem now, when i entered an invalid char for player one it gives me the default response which is fine, but right below it it also states the comment "Tie with Paper!". So, back to pulling my hair and staring at the monitor for a while.

Seems to me that if you want to catch bad input by player 1 you need another "else if" along these lines...

else if (playerOne == 'P' || playerOne == 'p')

And the "else" should be an "invalid input" message. Right now "else" assumes player 1 entered something valid (paper).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.