> player; }while(player != 'r' && player != 'p' && player != 's'); return player; } char getComputerChoice(){ srand(time(0)); int num = rand() % 3 + 1; switch(num){ case"> > player; }while(player != 'r' && player != 'p' && player != 's'); return player; } char getComputerChoice(){ srand(time(0)); int num = rand() % 3 + 1; switch(num){ case"> > player; }while(player != 'r' && player != 'p' && player != 's'); return player; } char getComputerChoice(){ srand(time(0)); int num = rand() % 3 + 1; switch(num){ case">
#include <iostream>
#include<ctime>
using namespace std;
char getUserChoice();
char getComputerChoice();
void showChoice(char choice);
void chooseWinner(char player, char computer);
int main(){
char player;
char computer;
player = getUserChoice();
cout << "Your choice: ";
showChoice(player);
computer = getComputerChoice();
cout << "Computer's choice: ";
showChoice(computer);
chooseWinner(player, computer);
}
char getUserChoice(){
char player;
cout << "Rock, Papaer, Scissors Game! \\n";
cout << "**************************** \\n";
do{
cout << "Choose one of the following\\n";
cout << "'r' for rock \\n";
cout << "'p' for paper \\n";
cout << "'s' for scissors \\n";
cin >> player;
}while(player != 'r' && player != 'p' && player != 's');
return player;
}
char getComputerChoice(){
srand(time(0));
int num = rand() % 3 + 1;
switch(num){
case 1:
return 'r';
case 2:
return 'p';
case 3:
return 's';
}
return 0;
}
void showChoice(char choice){
switch(choice){
case 'r':
cout << "Rock\\n";
break;
case 'p':
cout << "Paper\\n";
break;
case 's':
cout << "Scissors\\n";
break;
}
}
void chooseWinner(char player, char computer){
switch(player){
case 'r':
if(computer == 'r'){
cout << "It's a tie\\n";
}else if (computer == 'p'){
cout << "You lose\\n";
}else{
cout << "You win\\n";
}
break;
case 'p':
if(computer == 'r'){
cout << "You win\\n";
}else if (computer == 'p'){
cout << "You tie\\n";
}else{
cout << "You lose\\n";
}
break;
case 's':
if(computer == 'r'){
cout << "You lose\\n";
}else if (computer == 'p'){
cout << "You win\\n";
}else{
cout << "You tie\\n";
}
break;
}
}