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

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;
}

 

Related Content
Rock paper scissors in C#
Rock paper scissors in C#
Samath | Jan 01, 2021
Paper Strip Game using Python
Paper Strip Game using Python
Samath | Jan 17, 2024
The Matching Game in Java
The Matching Game in Java
Samath | Mar 20, 2015
Hangman Game in C++
Hangman Game in C++
Samath | Jan 17, 2024
Hangman Game using C#
Hangman Game using C#
Samath | Jan 17, 2024
Animal Game in Java
Animal Game in Java
gideonna | Apr 13, 2016
Number Guessing Game using C++
Number Guessing Game using C++
Samath | Jan 04, 2017
Blackjack Game in C++
Blackjack Game in C++
Samath | Jan 05, 2017
Checkers Game using C++
Checkers Game using C++
Samath | Jan 17, 2024
Minesweeper Game using C++
Minesweeper Game using C++
Samath | Jan 05, 2017
Craps Dice game in C++
Craps Dice game in C++
Samath | Jan 06, 2021
Tic Tac Toe Game using C#
Tic Tac Toe Game using C#
Samath | Jan 17, 2024