Rock Paper Scissors Game

 avatar
unknown
c_cpp
a year ago
1.9 kB
9
Indexable
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <stdlib.h> 
using namespace std;


int main(){
	//if user inpu is () and comp. input is ()
	
	// user's input options
	string computerChoice[3] = {"Rock", "Paper", "Scissors"};
	char R, P, S, E;
	char userInput;
	
	//messages for results
	string TIE = "Tie \n";
	string WIN = "You won \n";
	string LOSE = "Computer won \n";
	
	cout << "(Press E to exit) \n";
	cout << "Instructions: Press R for rock, P for paper, S for scissors \n";
	//add score inside the game loop don't we?
	
	
	//GAME LOOP
	while (userInput != 'E'){
		// for random or something idk how it works it just does
		//does it not seem random this time??
		srand(time(NULL));
		int random = (rand() % 3);
		
		//add a score counter to piss them off
		int userScore;
		int computerScore;
		
		cout << "  \n";
		cout << "  \n";
		cout << "Rock Paper Scissors \n";
		cout << "  \n";
		cout << "You: ";
		cin >> userInput;
		cout << "Computer: " << computerChoice[random] << endl;
	
		//each of these mean a tie?
		if (userInput == 'R' && random == 0 || userInput == 'P' && random == 1 || userInput == 'S' && random == 2 ){
			cout << TIE;	
		}
		
		//result for victory
		if (userInput == 'R' && random == 2 || userInput == 'P' && random == 0 || userInput == 'S' && random == 1){
			userScore++;
			cout << WIN;
			cout << "Score: \n";
			cout << "Computer: " << computerScore << endl;
			cout << "You: " << userScore << endl;
		}
		
		//result for defeat
		if (userInput == 'R' && random == 1 || userInput == 'P' && random == 2 || userInput == 'S' && random == 0){
			computerScore++;
			cout << LOSE;
			cout << "Computer: " << computerScore << endl;
			cout << "You: " << userScore << endl;
		}
		
		// 0 = rock         1 = paper         2 = scissor
	}
	
	if (userInput == 'E'){
		return 0;
	}
	
	
}