A program that lets the user play the game of Rock, Paper, Scissors against the computer.
Step-by-step explanation:
a. When the program begins, the user enters his or her choice of "rock", "paper", or "scissors" at the keyboard using a menu in a function, userChoice, that returns a character.
b. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. (NOTE: You’ll have to do some research on how to create random numbers correctly.) If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. The computer’s choice is returned as a character
c. After, a function, determineWinner, will determine the winner between the user’s choice vs. the computer’s choice.The result is selected according to the following rules:
d. Finally, after a result is selected, there should be a function, playAgain, in which the player should have the option of playing again. This should return a boolean.
#include <iostream>
#include <stdlib.h>
int main() {
srand (time(NULL));
int computer = rand() % 3 + 1;
int user = 0;
std::string roc = "1) Rock\\";
std::string pap = "2)Paper\\";
std::string sci = "3) Scissors\\";
std::cout << "rock paper scissors!\\";
std::cout << roc;
std::cout << pap;
std::cout << sci;
std::cout << "Choose: ";
std::cin >> user;
std::cout << "\\You choose ";
switch(user){
case 1 :
std::cout << roc;
break;
case 2 :
std::cout << pap;
break;
case 3 :
std::cout << sci;
break;
default :
std::cout << "Invalid Option\\";
}
std::cout << "Comp choose ";
switch(computer){
case 1 :
std::cout << roc;
break;
case 2 :
std::cout << pap;
break;
case 3 :
std::cout << sci;
break;
default :
std::cout << "Invalid Option\\";
}
if(user == computer){
std::cout << "Draw Game\\";
}
else if(user == 1 && computer == 3){
std::cout << "You Win\\";
}
else if(user == 3 && computer == 2){
std::cout << "You Win\\";
}
else if(user == 2 && computer == 1){
std::cout << "You Win\\";
}
else{
std::cout << "Computer Wins!\\";
}
}