RPS Logic?

Here’s the issue that I’m having. There’s 2 but one more important than the other.

  1. the srand doesn’t seem to be giving random items. When I’m looking at the function it seems to be correct. Here is what is happening.
    The computer value seems to be putting out 2 and that’s it. no matter the time. I tried moving functions around in different orders and it seems that doesnt work.
    The other issue that im having is that even when it adds the 1 to the non random number, it still sees it as 1.
    So the output is displaying 2 but the if statements see 1.

So when ever i test it, it says it ties when i play rock, and loose when i play paper. Though its giving the result of paper.

Second issue is less important but how in the world do you put emojis in code lol. Here’s the code that I have.

Well, it’s important to consider how the random seed works. If you’re doing it by time it’s still an approximation of how randomness might work, and you might caught in long rows of one result depending on your timing (you can look into other random number generators). It should still be random. There’s nothing wrong with your random code (try looping it a hundred times printing it to confirm for yourself).

So then the problem logically had to be somewhere else…

Problem in your code is you’re not comparing, you’re assigning. You need the double == to compare.

if (user == 1) {

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

should be

if (user == 1) {

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

}
2 Likes

As for emojis, you need to use utf-8:

std::cout << "\U0001F600" << std::endl;

Here’s a nice intro to utf-8

1 Like

Thanks a bunch. I thought the == was used with inputs, that seems to where i get stuck on the most.

1 Like