Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is wrong with my if statements? [closed]

Tags:

c++

I've tried different ways of laying out my if statements, I even tried nested if statements. I get the same result. I'm not sure of any way to ask my question besides showing my code.

#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main()
{
char playerOne, playerTwo;

cout<<"ROCK PAPER SCISSORS!"<<endl;
cout<<"Enter P for Paper"<<endl;
cout<<"Enter R for Rock"<<endl;
cout<<"Enter S for Scissors"<<endl;

cout<<"Player One enter your choice: ";
cin>>playerOne;

cout<<"Player Two enter your choice: ";
cin>>playerTwo;

if ((playerOne = 'R') && (playerTwo = 'R'))
    cout<<"Both players played same hand";
else if ((playerOne = 'R') && (playerTwo = 'P'))
    cout<<"Player Two wins!";
else if ((playerOne = 'R') && (playerTwo = 'S'))
    cout<<"Player One wins!";
else if ((playerOne = 'P') && (playerTwo = 'R'))
    cout<<"Player One wins!";
else if ((playerOne = 'P') && (playerTwo = 'P'))
    cout<<"Both players played same hand";
else if ((playerOne = 'P') && (playerTwo = 'S'))
    cout<<"Player Two wins!";
else if ((playerOne = 'S') && (playerTwo = 'R'))
    cout<<"Player Two wins!";
else if ((playerOne = 'S') && (playerTwo = 'P'))
    cout<<"Player One wins!";
else if ((playerOne = 'S') && (playerTwo = 'S'))
    cout<<"Both players played same hand";
else
    cout<<"Invalid inputs!";

getche();
return 0;
}
like image 587
gosutag Avatar asked Nov 29 '25 06:11

gosutag


1 Answers

you need the double == sign instead of =

== can be read as "is equal to"

like image 180
ajon Avatar answered Nov 30 '25 19:11

ajon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!