Output Code

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <iostream>

#include <cstdlib>
#include <ctime>

int main() {
std::srand(std::time(nullptr));

int choice;
int computerChoice;
int userScore = 0;
int computerScore = 0;

while (true) {
std::cout << "Choose an option:\n";
std::cout << "1. Rock\n";
std::cout << "2. Paper\n";
std::cout << "3. Scissors\n";
std::cout << "4. Quit\n";
std::cin >> choice;

if (choice == 4) {
break;
}

computerChoice = std::rand() % 3 + 1;

std::cout << "You chose: ";


switch (choice) {
case 1:
std::cout << "Rock\n";
break;
case 2:
std::cout << "Paper\n";
break;
case 3:
std::cout << "Scissors\n";
break;
default:
std::cout << "Invalid choice\n";
continue;
}

std::cout << "Computer chose: ";


switch (computerChoice) {
case 1:
std::cout << "Rock\n";
break;
case 2:
std::cout << "Paper\n";
break;
case 3:
std::cout << "Scissors\n";
break;
}

if (choice == computerChoice) {
std::cout << "It's a tie!\n";
} else if (
(choice == 1 && computerChoice == 3) ||
(choice == 2 && computerChoice == 1) ||
(choice == 3 && computerChoice == 2)
) {
std::cout << "You win!\n";
userScore++;
} else {
std::cout << "Computer wins!\n";
computerScore++;
}

std::cout << "Your score: " << userScore << "\n";


std::cout << "Computer score: " << computerScore << "\n";
}

return 0;
}

You might also like