C++ Rock Paper Scissors Game
Posted by Samath
Last Updated: January 05, 2017
  1454

This is a simple rock, paper, scissors game using the c++ programming language. The program basically ask the user to enter there choice and compare it with the computer's choice and determine the winner based on the comparison. An example of a simulation would be that if the user chose rock and the computer chose paper, the computer would be the winner because paper covers rock. 

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

using namespace std;

int main()
{
	do{
		string user;
		int computer;
		cout << "Enter rock, paper, or scissors: " ;
		cin >> user;

		cout << "Your Choice: " << user << endl;

		srand(time(NULL));

		computer = rand() % 10 + 1;

		if (computer <= 3)
		{
			cout << "Computer chose: Rock" << endl;
			cout << " " << endl;
		}
		else if (computer <= 6)
		{
			cout << "Computer chose: Paper" << endl;
			cout << " " << endl;
		}
		else if (computer >= 7)
		{
			cout << "Computer chose: Scissors" << endl;
			cout << " " << endl;
		}
		if (user == "rock" && computer <= 3)
		{
			cout << "It's a tie!" << endl;
			cout << " " << endl;
		}
		else if (user == "rock" && computer <= 6)
		{
			cout << "You lose!" << endl;
			cout << " " << endl;
		}
		else if (user == "rock" && computer >= 7)
		{
			cout << "You win!" << endl;
			cout << " " << endl;
		}
		if (user == "paper" && computer <= 3)
		{
			cout << "You win!" << endl;
			cout << " " << endl;
		}
		else if (user == "paper" && computer <= 6)
		{
			cout << "It's a tie!" << endl;
			cout << " " << endl;
		}
		else if (user == "paper" && computer >= 7)
		{
			cout << "You lose!" << endl;
			cout << " " << endl;
		}
		if (user == "scissors" && computer <= 3)
		{
			cout << "You lose!" << endl;
			cout << " " << endl;
		}
		else if (user == "scissors" && computer <= 6)
		{
			cout << "You win!" << endl;
			cout << " " << endl;
		}
		else if (user == "scissors" && computer >= 7)
		{
			cout << "It's a tie!" << endl;
			cout << " " << endl;
		}
	} while (cin.get());

	cin.get();
	return 0;
}