Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RPS.cpp #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 100 additions & 90 deletions 3-conditionals-and-logic/rock-paper-scissors-lizard-spock/RPS.cpp
Original file line number Diff line number Diff line change
@@ -1,98 +1,108 @@
/*
C++ codecademy project rock, paper, scissors
description :
1. Prompts the user to select either Rock, Paper, Scissors, Lizard, or Spock.
2. Insruct the computer to randomly select either Rock, Paper, Scissors, Lizard or Spock.
3. Compares the user's choice and the computer's choice and determine the winner.
4. Informs the user who the winner is

Instruct logic to win the game :
1. Scissors cuts Paper.
2. Papers covers Rock.
3. Rock crushed Scissors
*/
#include <iostream>
#include <cstdlib>

int main() {

srand(time(NULL));

int computer = std::rand() % 3 + 1;

int user;

std::cout << "====================\n";
std::cout << "rock paper scissors!\n";
std::cout << "====================\n";

std::cout << "1) ✊\n";
std::cout << "2) ✋\n";
std::cout << "3) ✌️\n";

std::cout << "shoot! ";

std::cin >> user;

if (user == 1)
std::cout << "you choose: ✊\n";
else if (user == 2)
std::cout << "you choose: ✋\n";
else
std::cout << "you choose: ✌️\n";

if (computer == 1)
std::cout << "cpu choose: ✊\n";
else if (computer == 2)
std::cout << "cpu choose: ✋\n";
else
std::cout << "cpu choose: ✌️\n";


if (user == computer) {

std::cout << "it's a tie!\n";

}

// user rock

else if (user == 1) {

if (computer == 2) {

std::cout << "you lost! booooo!\n";

}
if (computer == 3) {

std::cout << "you won! woohoo!\n";

}

}

// user paper

else if (user == 2) {

if (computer == 1) {

std::cout << "you won! woohoo!\n";

}
if (computer == 3) {

std::cout << "you lost! boo!\n";

#include <stdlib.h>
#include <string>

int main (){

// make random computer choice
srand (time(NULL));

int computer_input = rand() % 3 + 1;
int user_input = 0;
std::string computer_shoot;
std::string user_shoot;
std::string result_winner;

std::cout << "================================================\n";
std::cout << "Welcome to challenge game rock, paper, scissors \n\n";

std::cout << "1) ✊ Rock \n";
std::cout << "2) ✋ Paper \n";
std::cout << "3) ✌ Scissors \n";
std::cout << "Choice your answer : ";
std::cin >> user_input;
std::cout << "\n";

std::cout << "Result Shoot : \n";
// Make logic conditional for user shoot
if (user_input == 1){
user_shoot = "✊ Rock";
} else if (user_input == 2){
user_shoot = "✋ Paper";
} else if (user_input == 3){
user_shoot = "✌ Scissors";
} else {
user_shoot = "Error invalid input from user input (1 to 3)";
}

}

// user scissors

else if (user == 3) {

if (computer == 1) {

std::cout << "you won! woohoo!\n";

// Make logic conditional for computer shoot
if (computer_input == 1 && (user_input == 1 || user_input == 2 || user_input == 3)){
computer_shoot = "✊ Rock";
} else if (computer_input == 2 && (user_input == 1 || user_input == 2 || user_input == 3)){
computer_shoot = "✋ Paper";
} else if (computer_input == 3 && (user_input == 1 || user_input == 2 || user_input == 3)){
computer_shoot = "✌ Scissors";
} else if ((computer_input == 1 && computer_input == 2 || computer_input == 3) || (user_input != 1 || user_input != 2 || user_input !=3)){
computer_shoot = "Error invalid computer shoot from user input";
} else {
computer_shoot = "Error";
}
if (computer == 2) {

std::cout << "you lost! booooo!\n";

// Code to make conditional logic to win win result
if (computer_input == 1){
if (user_input == 1){
result_winner = "= Equal seri";
} else if (user_input == 2){
result_winner = "😎 User Input";
} else if (user_input == 3){
result_winner = "💻 Computer Input";
} else {
result_winner = "Error - Invalid Input User";
}

} else if (computer_input == 2){
if (user_input == 1){
result_winner = "💻 Computer Input";
} else if (user_input == 2){
result_winner = "= Equal seri";
} else if (user_input == 3){
result_winner = "😎 User Input";
} else {
result_winner = "Error - Invalid Input User";
}

} else if (computer_input == 3){
if (user_input == 1){
result_winner = "😎 User Input";
} else if (user_input == 2){
result_winner = "💻 Computer Input";
} else if (user_input == 3){
result_winner = "= Equal seri";
} else {
result_winner = "Error - Invalid Input User";
}
} else {
result_winner = "Error - Program";
}

}

return 0;

std::cout << "User choice : " << user_shoot << "\n";
std::cout << "Computer choice : " << computer_shoot << "\n\n";
std::cout << "Comparison war (user vs computer) : " << user_shoot << " vs " << computer_shoot << "\n";
std::cout << "Result Winner Of : " << result_winner << "\n";
std::cout << "Thank For Play this game \n";
std::cout << "================================================\n";
return 0;
}