Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int getComputerChoice();
- int main()
- {
- int win = 0;
- int lose = 0;
- int tie = 0;
- int choice;
- int computer;
- int number;
- // Constants for the menu choices.
- const int Rock = 1,
- Paper = 2,
- Scissors = 3;
- //************************************************************
- // Definition of function showMenu which displays the menu. *
- //************************************************************
- void showMenu();
- {
- cout << "\n Lets play Rock, Paper, Scissors!\n\n"
- << "1. Rock\n"
- << "2. Paper\n"
- << "3. Scissors\n"
- << "Please enter your choice: ";
- cin >> choice;
- }
- // ********************************************************
- // The getComputerChoice function returns the computer's *
- // game choice. It returns 1 for rock (via the ROCK *
- // constant), or 2 for paper (via the PAPER constant), *
- // or 3 for scissors (via the SCISSORS constant). *
- // ********************************************************
- if (choice == 1 && computer == 1) {
- cout << "Rock meets Rock its a tie!" << endl;
- tie++;
- }
- else if (choice == 1 && computer == 2) {
- cout << "Rock is covered by Paper the computer wins!." << endl;
- lose++;
- }
- else if (choice == 1 && computer == 3) {
- cout << "Rock crushes Scissors you win!" << endl;
- win++;
- }
- else if (choice == 2 && computer == 1) {
- cout << "Paper covers Rock you win!" << endl;
- win++;
- }
- else if (choice == 2 && computer == 2) {
- cout << "Paper meets Paper its a tie!" << endl;
- tie++;
- }
- else if (choice == 2 && computer == 3) {
- cout << "Paper is cut by Scissors the computer wins!" << endl;
- lose++;
- }
- else if (choice == 3 && computer == 1) {
- cout << "Scissors are crushed by Rock computer wins!" << endl;
- lose++;
- }
- else if (choice == 3 && computer == 2) {
- cout << "Scissors cuts Paper you win!" << endl;
- win++;
- }
- else if (choice == 3 && computer == 3) {
- cout << "Scissors meet Scissors its a tie!" << endl;
- tie++;
- }
- // this is what happens if the player doesn't hit 1 2 or 3
- else {
- cout << "You didn't select 1, 2, or 3" << endl;
- }
- system("pause");
- return 0;
- }
- int getComputerChoice()
- {
- // Get the system time so we can use it
- // to seed the random number generator.
- unsigned seed = time(0);
- // Use the seed value to seed the random
- // number generator.
- srand(seed);
- // Generate a random number in the range of 1-3.
- int number = 1 + rand() % 3;
- // Return the random value.
- return number;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement