C++ programming!

profileaii.aei.ali1993

I need to fix the following code of the game " Paper, rock ,Scissor"

 

I have the code but there is a mistake in it

 

When Player1 Enter correct input (for example the input is r, R, p, P, s, S ) AND Player 2 Enter correct input>>>>>> There is no problem in the code.

 

When Player1 Enter Wrong input (for example the input is w, m, y or any letter ) AND Player 2 Enter wrong input>>>>>> There is no problem in the code.

 

 

BUT when Player1 enter  CORRECT input and Player 2 enter WRONG input, then I have problem in the code.

 

Could you fix the code PLEASE????

 

My code is:

 

 

#include <iostream>

 

using namespace std;

 

int main()

{

    char input1, input2, repeat;

    do {

        cout << "Player-1 turn! Enter your move. For rock press r/R, for paper press p/P, and for scissor press s/S, please! " << endl;

        cin >> input1;

        cout << "Player-2 turn! Enter your move. For rock press r/R, for paper press p/P, and for scissor press s/S please! " << endl;

        cin >> input2;

 

        if  (input1 != 'r' && input1 != 'R'   // if which checks the both inputs CLOSING

            && input1 != 'p' && input1 != 'P'

            && input1 != 's' && input1 != 'S'

            && input2 != 'r' && input2 != 'R'

            && input2 != 'p' && input2 != 'P'

            && input2 != 's' && input2 != 'S')

        {

            cout << "You have entered wrong input!! " << endl;

        }

 

        else if (input1 == 'r' || input1 == 'R')

        {

            if (input2 == 'p' || input2 == 'P')

            {

                cout << "Paper defeat the rock!" << endl;

                cout << "Player 2 wins the game!" << endl;

            }

 

            else if (input2 == 's' || input2 == 'S')

            {

                cout << "Scissor defeat the paper!" << endl;

                cout << "Player 1 wins the game!" << endl;

            }

 

            else // if input2 == 'R' || 'r'

            {

                cout << "Rock will not defeat other rock!" << endl;

                cout << "Tie! Neither Player 1 nor Player 2 won the game! " << endl;

            }

        } // CLOSING LOOP for player 1 when he input R

 

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

        {

            if ((input2 == 'r') || (input2 == 'R'))

            {

                cout << "Paper defeats rock!" << endl;

                cout << "Player 1 is the winner!" << endl;

            }

 

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

            {

                cout << "Paper will not defeat other paper!" << endl;

                cout << "Tie! Neither Player 1 nor Player 2 won the game! " << endl;

            }

 

            else //if (input2 == 's' || input2 == 'S')

            {

                cout << "Scissor will defeat paper!" << endl;

                cout << "Player 2 is the winner!" << endl;

            }

        } // CLOSING LOOP if the 1st player enters p or P

 

        else //if (input1 == 's' || input1 == 'S')

        {

            if ((input2 == 'r') || (input2 == 'R'))

            {

                cout << " Rock will defeat scissor" << endl;

                cout << "Player 2 is the winner!" << endl;

            }

 

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

            {

                cout << "Scissor will defeat paper" << endl;

                cout << "Player 1 is the winner!" << endl;

            }

 

            else //if Player 2 choose 'S'||'s'

            {

            cout << "Scissor will not defeat other scissor! " << endl;

            cout << "Tie! Neither Player 1 nor Player 2 won the game! " << endl;

            }

        } //CLOSING LOOP if player 1 choose scissor

 

        cout << "Do You Want to play again?" << endl;        // Ask the player if he want to repeat the game

        cout << "Press Y for Yes or any key to quit the game!" << endl;

        cin >> repeat;

 

    } while ((repeat == 'Y') ||(repeat == 'y')); //do while CLOSING

 

    return 0;

} // main int CLOSING

    • 11 years ago
    • 5
    Answer(1)

    Purchase the answer to view it

    blurred-text
    NOT RATED
    Bids(0)