Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * BouknechtChadd_P4.cpp
- *
- * Created on: Sep 28, 2016
- * Author: Chadd Bouknecht (Created on Aureas WS)
- */
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- using namespace std;
- int totalGames, totalWins, totalTies;
- int playerChoice, computerChoice, winloseTie;
- string playerChoice1, gameOutcome;
- char playGame;
- int determineWinner(playerChoice, computerChoice);
- int main() {
- cout << "Would you like to play a game of rock, paper, scissors, lizard, Spock? Enter Y for yes or N for no." << endl;
- cin << playGame;
- cin.ignore();
- //Validates player selection
- while(playGame != 'Y' && playGame != 'y' && playGame != 'N' && playGame != 'n')
- {
- cout << "Invalid Selection. Please enter Y for yes or N for no." << endl;
- cin playGame;
- cin.ignore();
- }
- //Game loop
- do
- {
- //Adds one to total games
- totalGames += 1;
- //Generates random computer choice
- srand(time(NULL));
- computerChoice = rand() % 5;
- //Prompts for user choice
- cout << "What is your choice? Enter 0 for rock, 1 for paper, 2 for scissors, 3 for lizard, or 4 for Spock.";
- cin playerChoice;
- cin.ignore();
- //Validates User input
- while(playerChoice != 0 && playerChoice != 1 && playerChoice != 2 && playerChoice != 3 && playerChoice != 4) {
- cout << "Invalid choice. Enter 0 for rock, 1 for paper, 2 for scissors, 3 for lizard, or 4 for Spock.";
- cin playerChoice;
- cin.ignore();
- }
- //Sets a string for user choice display
- if(playerChoice == 0)
- playerChoice1 = "Rock";
- else if(playerChoice == 1)
- playerChoice1 = "Paper";
- else if(playerChoice == 2)
- playerChoice1 = "Scissors";
- else if(playerChoice == 3)
- playerChoice1 = "Lizard";
- else if(playerChoice == 4)
- playerChoice = "Spock";
- //Displays User choice
- cout << "Your choice is " << playerChoice1 << " ." << endl;
- //Determines Winner
- int determineWinner(playerChoice, computerChoice);
- //Sets string for the outcome of the game
- if(winloseTie == -1)
- gameOutcome = "lost";
- else if(winloseTie == 0)
- gameOutcome = "tied";
- else if(winloseTie == 1)
- gameOutcome = "won";
- //Displays outcome of game
- cout << "You have " << gameOutcome << " ." << endl;
- cout << "Would you like to play again? Enter Y for yes, or N for no." << endl;
- cin << playGame;
- cin.ignore();
- //Validates selection (AGAIN)
- while(playGame != 'Y' && playGame != 'y' && playGame != 'N' && playGame != 'n')
- {
- cout << "Invalid Selection. Please enter Y for yes or N for no." << endl;
- cin playGame;
- cin.ignore();
- }
- }
- while(playGame == 'Y' || playGame == 'y');
- //End of game. If player chooses not to play another games.
- cout << "Thank you for playing! Your stats are:/n";
- cout << "Total wins: " << totalWins << endl;
- cout << "Total ties: " << totalTies << endl;
- cout << "Total games: " << totalGames << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement