Fooji
Fooji

Reputation: 71

Rock/Paper/Scissors game not working correctly

I'm in a beginning computer science class and for my next project I am supposed to make a rock, paper, scissors game.

The games isnt finished yet as I still need to add score keeping and input recommendations (Oh what I should have chosen more often), and loops.

My question however, I wanted to test how the game to see if it works up until this point. The code compiles correctly, but once I input my decision and the computer inputs it's decision, the "winner" is not correct.

so for example:

Player chooses Rock

Computer chooses Scissors

It's a TIE

I thought that maybe I input some of my if-statements incorrectly as some of the answers I chose come out correctly (on who's the actual winner), and some don't.

But after going back to my code and checking them all (multiple times), they seem correct to me...

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()

{ // MAIN bracket OPEN

char YorN;
char player;
int computer;

srand(time(NULL));


cout << "****************************************************************************************" << endl;
cout << "**********************************ROCK PAPER SCISSORS***********************************" << endl;
cout << "****************************************************************************************\n\n"<< endl ;

cout << "---Rules of the game is simple. Choose R for Rock, P for Paper, and S for Scissors---\n";
cout << "---Whoever with the most wins, will be crowned victorious ---\n\n";
cout << "Do you think you can beat me? (Y or N): ";

cin >> YorN;
cout << "\n\n\n";

cout<< "NOTE:::: Whenever you're done playing the game, press ( E ) to Exit the game::::" << endl;


if(YorN=='Y' || YorN == 'y')
{ // if statement OPEN

    cout << "\nAlright, lets see what you got! "<< endl;

} // if statement CLOSED

else
{ // else staement OPEN

    cout<< "\nWow, I beat you without even trying. \nI am VICTORIOUS!!" << endl;

    return(0);
} // else statement CLOSED

cout<< "Okay, here we go...\n";
cout<<".\n.\n.\n.\n.\n.\n.\n..." ;
cout << "Choose ( R ) for Rock, ( P ) for Paper, ( S ) for Scissors: " ;

cin >> player;
cout <<"\n\n";
switch(player)
{ // Switch statement OPEN

    case 'R':
            cout<< "Player chooses Rock " <<endl;
            break;
    case 'r':
            cout<< "Player chooses Rock " <<endl;
            break;
    case 'P':
            cout<<"Player chooses Paper "<< endl;
            break;
    case 'p':
            cout<<"Player chooses Paper "<< endl;
            break;
    case 'S':
            cout<<"Player chooses Scissors "<< endl;
            break;
    case 's':
            cout<<"Player chooses Scissors "<<endl;
            break;
    default:
            cout<<"That is no a correct input "<< endl;

} // Switch statement CLOSED

computer = rand() % 3 + 1;

switch(computer)
{ // Switch statement computer OPEN

    case 1:
            cout<< "Computer chooses Rock "<< endl;
            break;
    case 2:
            cout<< "Computer chooses Paper "<< endl;
            break;
    case 3:
            cout<< "Computer chooses Scissors "<< endl;
            break;


} // Swithch staement computer CLOSED

if(player=='r' || player=='R' && computer==1)
{ // if statement OPEN

    cout<< "***It's a TIE***" << endl;

} // if Statement CLOSED

else if(player=='r' || player=='R' && computer==2)
{ // if else statement1 OPEN
cout<<"***Computer WINS***"<< endl;

} // if else statement1 CLOSED
else if(player=='r' || player=='R' && computer==3)
{ //else if statement2 OPEN

    cout<<"***Player WINS***"<< endl;

} //else if statement2 CLOSED
else if(player=='p' || player=='P' && computer==1)
{ //else if statement3 OPEN

    cout<<"***Player WINS***"<<endl;

} // else if statement3 CLOSED

else if(player=='p' || player=='P' && computer==2)
{ // else if statement4 OPEN

    cout<<"***It's a TIE***"<< endl;

} // else if statement4 CLOSED

else if(player=='p' || player=='P' && computer==3)
{ // else if statement5 OPEN

    cout<<"***Computer WINS***"<<endl;

} // else if statement5 CLOSED
else if(player=='s' || player=='S' && computer==1)
{ // else if statement6 OPEN

    cout<< "***Computer WINS***" << endl;

} // else if statment6 CLOSED

else if(player=='s' || player=='S' && computer==2)
{ // else if statement7 OPEN

    cout<< "***Player WINS***"<< endl;

} // eses if statement7 CLOSED

else if(player=='s' || player=='S' && computer==3)
{ // else if statement8 OPEN

    cout<< "***It's a TIE***" << endl;

} // else if statement8 CLOSED

} // MAIN bracket CLOSED

Again, the coding isn't complete. I still have to add some things.

Also I'm sorry, I'm still new to coding. Forgive me if I am not thorough enough about my problem or if I added too much on the code page... I didn't know which parts to include or exclude

Upvotes: 1

Views: 57

Answers (1)

donpsabance
donpsabance

Reputation: 368

Fix ALL the brackets for the if statements

Example

From:

if(player=='r' || player=='R' && computer==1){

To:

if((player=='r' || player=='R') && computer==1){ 

Upvotes: 1

Related Questions