Can anyone help figure out why this rock,paper,scissors program is giving me muliple answers

https://www.codecademy.com/courses/learn-c-plus-plus/projects/rock-paper-scissors-lizard-spock

why is this program giving me more then one answer?

#include
#include <stdlib.h>
#include <time.h>

int main(){
srand(time(NULL));
int user;
int computer= std::rand()%3+1;

std::cout<<"Lets play rock, paper, scissors!\n";
std::cout<<"1)rock\n";
std::cout<<"2)paper\n";
std::cout<<"3)scissors\n";
std::cin>>user;
if(user==1){
    std::cout<<"You entered rock\n";
    
}
else if(user ==2){
    std::cout<<"You entered paper\n ";
}
else if (user == 3){
    std::cout<<"You entered scissors\n";
}
else{
    std::cout<<"invalid input\n";
}

if(computer==1){
    std::cout<<"computer entered rock\n";
    
}
else if(computer ==2){
    std::cout<<"computer entered paper\n ";
}
else if (computer == 3){
    std::cout<<"computer entered scissors\n";
}

if(user == computer){
std::cout<<“its a tie\n”;
}

else if (user=1){
 
     if(computer=2){
       std::cout<<"you lose\n";
    }
     if(computer=3){
        std::cout<<"you win\n";
    }
    

}

else if(user = 2){
    

if(computer=1){
    std::cout<<"you win\n";
}
if(computer=3){
    std::cout<<"you lose\n";
}
}
else if(user=3){
    if(computer=1){
        std::cout<<"you lose\n";
    }
    if(computer=2){
        std::cout<<"you win\n";
    }
}

return 0;
}

You should double check your if else statements. Make sure you’re using a relational operator.

3 Likes