Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 21, 2021 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/5d556c5083f80c103473ca590d2823e4 to your computer and use it in GitHub Desktop.
Save codecademydev/5d556c5083f80c103473ca590d2823e4 to your computer and use it in GitHub Desktop.
Codecademy export
#include<iostream>
#include<cstdlib>
int main() {
int x; //represent the users's choice
int y; //represent the comp's random choice
//instruct the user to select
std::cout << "Make your choice by inputing the number:\n";
std::cout << "0) Rock\n";
std::cout << "1) Paper\n";
std::cout << "2) scissors\n";
std::cout << "3) Lizard\n";
std::cout << "4) Spock\n";
std::cin >> x;
//generate the computer's random choice
srand(time(NULL));
y = std::rand() % 5;
//test if y is the one we want
//std::cout << y << "\n";
//show what we've selected
switch(x) {
case 0:
std::cout << "You: " << "Rock\n";
break;
case 1:
std::cout << "You: " << "Paper\n";
break;
case 2:
std::cout << "You: " << "Scissors\n";
break;
case 3:
std::cout << "You: " << "Lizard\n";
break;
case 4:
std::cout << "You: " << "Spock\n";
break;
default:
std::cout << "Invalid input!\n";
break;
}
switch(y) {
case 0:
std::cout << "Computer: " << "Rock\n";
break;
case 1:
std::cout << "Computer: " << "Paper\n";
break;
case 2:
std::cout << "Computer: " << "Scissors\n";
break;
case 3:
std::cout << "Computer: " << "Lizard\n";
break;
case 4:
std::cout << "Computer: " << "Spock\n";
break;
default:
std::cout << "Invalid input!\n";
break;
}
//decide who wins
if(x == y) {
std::cout << "Tied\n";
}
else if(x == 0 && (y == 2 || y == 3)) {
std::cout << "You win\n";
}
else if(x == 0 && (y == 1 || y == 4)) {
std::cout << "You loose\n";
}
else if(x == 1 && (y == 0 || y == 4)) {
std::cout << "You win\n";
}
else if(x == 1 && (y == 2 || y == 3)) {
std::cout << "You loose\n";
}
else if(x == 2 && (y == 1 || y == 3)) {
std::cout << "You win\n";
}
else if(x == 2 && (y == 0 || y == 4)) {
std::cout << "You loose\n";
}
else if(x == 3 && (y == 1 || y== 4)) {
std::cout << "You win\n";
}
else if(x == 3 && (y == 0 || y == 2)) {
std::cout << "You loose\n";
}
else if(x == 4 && (y == 0 || y == 2)) {
std::cout << "You win\n";
}
else if(x == 4 && (y == 1 || y == 3)){
std::cout << "You loose\n";
}
else {
std::cout << "Something wrong!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment