An error regarding the rock and paper (rock paper scissors project)


#1

Hey guys,

I’m trying to do the “Rock Paper Scissors” project, but am receiving an error saying I did an invalid conversation from ‘const char*’ to ‘int’ in the code if (user = rock) and if (user = paper). I don’t get why it is saying this.

Here’s all my code:

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

int main() {
  srand (time(NULL));
  
  int computer = rand() % 3 + 1;
  
  int user;
  
  std::cout << "rock paper scissors:\n";
  
  std::cout << "1\n";
  std::cout << "2\n";
  std::cout << "3\n";
  
  std::cout << "shoot!\n";
  
  std::cin >> user;
  
  int usernumber = 0;
  
  if (user = "rock") {
    usernumber = 1;
  }
	else if (user = "paper") {
    usernumber = 2;
  }
}

Also, here is a screenshot of the error:


#2

Bumping topic up to top after 24hrs of no reply.


#3

You used the assignment operator instead of the comparator

user = “paper” attempts to set the int user to the string paper