ROCK, PAPER AND SCISSORS
include <iostream>
#include <iomanip>
#include <string>
using namespace std;
char userinput; int wincount, gamescount;
enum objtype { rock, paper, scissor}; objtype playerobject, cpuobject;
objtype playerselection (char playerinput); objtype cpuselection();
string show_obj_player, show_obj_computer;
void winner();
int main(){
char resp;
do{ cout << "Choose rock (r), paper (p) or scissor (s)" << endl; cin >> userinput;
winner(); cout << endl << "Player --> " << show_obj_player << " Cpu --> " << show_obj_computer << endl<<endl;
cout << "Do you want to try again?"; cin >> resp;
} while (resp == 'y');
system("pause");
}
objtype playerselection(char playerinput){ if (playerinput == 'r'){ playerobject = rock; show_obj_player = "rock"; return playerobject; } else if (playerinput == 'p'){ playerobject = paper; show_obj_player = "paper"; return playerobject; } else playerobject = scissor; show_obj_player = "rock"; return playerobject;
}
objtype cpuselection(){ int numrand;
srand(time(NULL)); numrand = 0 + rand() % ((2 + 1) - 0);
if (numrand == 0){ cpuobject = rock; show_obj_computer = "rock"; return cpuobject; } else if (numrand == 1){ cpuobject = paper; show_obj_computer = "paper"; return cpuobject; } else{ cpuobject = scissor; show_obj_computer = "scissor"; return cpuobject; }
};
void winner(){ objtype player, computer;
player = playerselection(userinput); computer = cpuselection();
if (player == computer) cout << "Draw"; else if (player == rock && computer == scissor) cout << "You win"; else if (player== rock && computer == paper) cout << "You loose"; else if (player == paper && computer == rock) cout << "You win"; else if (player == paper && computer == scissor) cout << "You loose"; else if (player == scissor && computer == paper) cout << "You win"; else if (player == scissor && computer == rock) cout << "You loose"; else cout << "Your selection is invalid";
}