Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Week 2 Assignment.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <cstdlib>
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- enum choice { Rock, Paper, Scissors };
- int user;
- choice select;
- choice cpu_select;
- int computer = rand();
- computer = rand() % 3;
- int num_ties = 0;
- bool tie = false;
- int player_wins = 0;
- int cpu_wins = 0;
- int num_ties = 0;
- int num_games = 0;
- string play;
- bool play_again;
- cout << "Please enter 'R' for Rock, 'P for Paper, or 'S for Scissors. ('r', 'p', or 's')" << endl;
- cin >> user;
- cout << endl;
- if (user == 'R') {
- select = Rock;
- } if (user == 'P') {
- select = Paper;
- } if (user == 'S') {
- select = Scissors; }
- { while (cpu_select == select) {
- cout << "It's a tie, try again";
- cin >> user;
- }
- choice cpu_select;
- if (computer == 0) {
- cpu_select = Rock;
- }
- else if (computer == 1) {
- cpu_select = Paper;
- }
- else if (computer == 2) {
- cpu_select = Scissors;
- }
- cout << endl << endl << "Your selection is " << select << endl;
- cout << endl << "The computer selects " << cpu_select << endl;
- bool you_win = false;
- if ((select == Rock && cpu_select == Scissors) || (select == Paper && cpu_select == Rock) || (select == Scissors && cpu_select == Paper)) {
- cout << endl << "You win" << endl;
- player_wins++;
- }
- else if ((cpu_select == Rock && select == Scissors) || (cpu_select == Paper && select == Rock) || (cpu_select == Scissors && select == Paper)) {
- cout << endl << "The computer wins" << endl;
- cpu_wins++;
- }
- else if (cpu_select == select) {
- num_ties++;
- }
- cout << endl << "You have won" << player_wins << " games and lost" << cpu_wins << "games" << endl;
- cout << endl << endl << "Would you like to play again?";
- cin >> play;
- if (play == 'N' || play == 'n') {
- play_again == false;
- }
- else if (play == 'Y' || play == 'y') {
- num_games++;
- }}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement