Advertisement
IdolizeDT

P6

Sep 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. /*
  2.  * BouknechtChadd_P4.cpp
  3.  *
  4.  *  Created on: Sep 28, 2016
  5.  *      Author: Chadd Bouknecht (Created on Aureas WS)
  6.  */
  7.  
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include <ctime>
  11. #include <string>
  12. using namespace std;
  13.  
  14. int totalGames, totalWins, totalTies;
  15. int playerChoice, computerChoice, winloseTie;
  16. string playerChoice1, gameOutcome;
  17. char playGame;
  18. int determineWinner(playerChoice, computerChoice);
  19.  
  20.  
  21.  
  22. int main() {
  23.  
  24.     cout << "Would you like to play a game of rock, paper, scissors, lizard, Spock? Enter Y for yes or N for no." << endl;
  25.     cin << playGame;
  26.     cin.ignore();
  27.    
  28.     //Validates player selection
  29.     while(playGame != 'Y' && playGame != 'y' && playGame != 'N' && playGame != 'n')
  30.     {
  31.         cout << "Invalid Selection. Please enter Y for yes or N for no." << endl;
  32.         cin playGame;
  33.         cin.ignore();
  34.     }
  35.    
  36.     //Game loop
  37.     do
  38.     {
  39.         //Adds one to total games
  40.         totalGames += 1;
  41.  
  42.         //Generates random computer choice
  43.         srand(time(NULL));
  44.         computerChoice = rand() % 5;
  45.  
  46.         //Prompts for user choice
  47.         cout << "What is your choice? Enter 0 for rock, 1 for paper, 2 for scissors, 3 for lizard, or 4 for Spock.";
  48.         cin playerChoice;
  49.         cin.ignore();
  50.  
  51.         //Validates User input
  52.         while(playerChoice != 0 && playerChoice != 1 && playerChoice != 2 && playerChoice != 3 && playerChoice != 4) {
  53.             cout << "Invalid choice. Enter 0 for rock, 1 for paper, 2 for scissors, 3 for lizard, or 4 for Spock.";
  54.             cin playerChoice;
  55.             cin.ignore();
  56.         }
  57.  
  58.         //Sets a string for user choice display
  59.  
  60.         if(playerChoice == 0)
  61.             playerChoice1 = "Rock";
  62.         else if(playerChoice == 1)
  63.             playerChoice1 = "Paper";
  64.         else if(playerChoice ==  2)
  65.             playerChoice1 = "Scissors";
  66.         else if(playerChoice == 3)
  67.             playerChoice1 = "Lizard";
  68.         else if(playerChoice == 4)
  69.             playerChoice = "Spock";
  70.  
  71.         //Displays User choice
  72.         cout << "Your choice is " << playerChoice1 << " ." << endl;
  73.  
  74.         //Determines Winner
  75.         int determineWinner(playerChoice, computerChoice);
  76.  
  77.         //Sets string for the outcome of the game
  78.         if(winloseTie == -1)
  79.             gameOutcome = "lost";
  80.         else if(winloseTie == 0)
  81.             gameOutcome = "tied";
  82.         else if(winloseTie == 1)
  83.             gameOutcome = "won";
  84.  
  85.         //Displays outcome of game
  86.         cout << "You have " << gameOutcome << " ." << endl;
  87.         cout << "Would you like to play again? Enter Y for yes, or N for no." << endl;
  88.         cin << playGame;
  89.         cin.ignore();
  90.        
  91.         //Validates selection (AGAIN)
  92.         while(playGame != 'Y' && playGame != 'y' && playGame != 'N' && playGame != 'n')
  93.             {
  94.                 cout << "Invalid Selection. Please enter Y for yes or N for no." << endl;
  95.                 cin playGame;
  96.                 cin.ignore();
  97.             }
  98.     }
  99.     while(playGame == 'Y' || playGame == 'y');
  100.    
  101.     //End of game. If player chooses not to play another games.
  102.     cout << "Thank you for playing! Your stats are:/n";
  103.     cout << "Total wins: " << totalWins << endl;
  104.     cout << "Total ties: "   << totalTies << endl;
  105.     cout << "Total games: " << totalGames << endl;
  106.     return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement