Rock Paper Scissors C++ Game
Indententation

Normally code is indented between { and }

int main()
{
    // Start here
}


Namespace

Never Do this.

using namespace std;


If you had read any other C++ review on this board it would have told you not to do this. See: Why is “using namespace std” in C++ considered bad practice?.

There is a reason that the standard libraries are called std and not standard. Its to make prefixing them easy.

Rand

Though your use of srand() and rand() is perfectly valid. This version of the random number generated is now obsolete. You should look up how to use the new random number functionality provided by C++11.

https://stackoverflow.com/a/14009667/14065
https://stackoverflow.com/a/19666713/14065

Note:

int computerNumber = rand() % 3 + 1;


This is slightly biased against 3. Assume RAND_MAX is 32768.

If you rolled 32768 times. Then your distribution would be.

1 10923/32768   
2 10923/32768
3 10922/32768  &lt;- Notice this is one smaller.


Invalid:

} else {
    std::cout &lt;&lt; "Congrats! You won!" &lt;&lt; endl;
}


Do you really want to have an invalid choice. You have already enumerated all the valid choices. If you get to this point there is a serious error in your code. So you need to indicate this (so you can catch it in testing).

else
{
    throw std::runtime_error("Error");
}


Data Driven Programming

Rather than write code to decide the winner:

if(computerChoice == "rock" &amp;&amp; userChoice == "rock") {
    std::cout &lt;&lt; "It was a tie!" &lt;&lt; endl;
} else if (computerChoice == "rock" &amp;&amp; userChoice == "scissors") {
    std::cout &lt;&lt; "The computer won! Better luck next time!" &lt;&lt; endl;
} else if (computerChoice == "paper" &amp;&amp; userChoice == "paper") {
    std::cout &lt;&lt; "It was a tie!" &lt;&lt; endl;
} else if (computerChoice == "paper" &amp;&amp; userChoice == "rock") {
    std::cout &lt;&lt; "The computer won! Better luck next time!" &lt;&lt; endl;
} else if (computerChoice == "scissors" &amp;&amp; userChoice == "scissors") {
    std::cout &lt;&lt; "It was a tie!" &lt;&lt; endl;
} else if (computerChoice == "scissors" &amp;&amp; userChoice == "paper") {
    std::cout &lt;&lt; "The computer won! Better luck next time!" &lt;&lt; endl;
} else {
    std::cout &lt;&lt; "Congrats! You won!" &lt;&lt; endl;
}


Use a data structure. Assume you translate the choices into a number for each user.

0 -&gt; rock
1 -&gt; paper
2 -&gt; scissor

// This array decides if who is the winner.
// 0 =&gt; Draw.
// 1 =&gt; Player 1
// 2 =&gt; Player 2
int winner[3][3] = {{0, 2, 1},
                    {1, 0, 2},
                    {2, 1, 0}};


// Then to decide the winner.
int theWinner = winner[player1Choice][player2Choice];


Advice


  In particular I couldn't find an efficient way to implement a play again feature.


To make things like retrying the code you need to start using functions so that you can logically compartmentalize your code.

int main()
{
    std::string name = getPlayerName();
    do
    {
        int player1 = getComputerMove();
        int player2 = getPlayerMove();
        displayWinner(player1, player2);
    }
    while(doesPlayerWantToContinue());
}