- 3

PLEASE EDIT THIS! BADLY NEEDED

PLEASE HELP ME WITH THIS

24th May 2017, 1:15 AM
eiro Jan
eiro Jan - avatar
5 Respostas
+ 8
I see no problem with the code. I just run it and the computer was picking randomly.
24th May 2017, 1:23 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 6
// Rearranged variables. // Added input validation. // Simplified if-else conditions. /* Made by Xander A. Appended by Hatsy Rei. Simple rock paper scissors game Please thumb up if you like it :) This is made for beginners to learn from, so you may copy this :) (If you copy then please leave ther line that says "Made by Xander A.") HAVE FUN! :) */ #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int selection = 0; string choice[3] = {"Rock", "Paper", "Scissors"}; string player_choice; string computer_choice; cout << "Made by Xander A." << endl; cout << "_________________" << endl << endl; cout << "Please select from the following list " << endl; cout << " 1) Rock " << endl; cout << " 2) Paper " << endl; cout << " 3) Scissors " << endl; while (selection < 1 || selection > 3) { cin >> selection; if (cin.fail() || selection < 1 || selection > 3) { cout << "Invalid selection. Please try again." << endl; cin.clear(); cin.ignore(512, '\n'); } } player_choice = choice[--selection]; computer_choice = choice[rand() % 3]; cout << "_________________" << endl << endl; cout << "The player chose " << player_choice << endl; cout << "The computer chose " << computer_choice << endl; cout << "_________________" << endl << endl; cout << "RESULTS" << endl; if (player_choice == computer_choice) cout << "The match ended in a tie!" << endl; else { switch(selection) { case 0: computer_choice == "Paper" ? cout << "You lost!" : cout << "You won!"; break; case 1: computer_choice == "Scissors" ? cout << "You lost!" : cout << "You won!"; break; case 2: computer_choice == "Rock" ? cout << "You lost!" : cout << "You won!"; break; } } return 0; }
24th May 2017, 4:37 AM
Hatsy Rei
Hatsy Rei - avatar
0
/* Made by Xander A. Simple rock paper scissors game Please thumb up if you like it :) This is made for beginners to learn from, so you may copy this :) (If you copy then please leave ther line that says "Made by Xander A.") ************COMMANDS**************** rock paper scissors HAVE FUN! :) */ #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); cout << "Made by Xander A." << endl << "------------" << endl << "GAME" << endl; string input; cin >> input; // making player input a string cout << "The player chose " << input << endl; //computer input string choices[3] = {"rock","paper","scissors"}; // array //chosen string from the array using the built-in rand function string chosen = choices[rand()%3]; //outputting what the computer chose cout << "The computer chose " << chosen << endl; cout << "-------------" << endl; cout << "RESULTS" << endl; //text values string tie = "Tie!"; string lost = "You lost!"; string won = "You won!"; //if statements if(input == chosen){ cout << tie; }else if(input == "rock" && chosen == "paper"){ cout << lost; }else if(input == "rock" && chosen == "scissors"){ cout << won; }else if(input == "rock" && chosen == "rock"){ cout << tie; }else if(input == "paper" && chosen == "rock"){ cout << won; }else if(input == "paper" && chosen == "scissors"){ cout << lost; }else if(input == "paper" && chosen == "paper"){ cout << tie; }else if(input == "scissors" && chosen == "rock"){ cout << lost; }else if(input == "scissors" && chosen == "paper"){ cout << won; }else if(input == "scissors" && chosen == "scissors"){ cout << tie; }else{ cout << "Invalid input"; } cout << "\nPlease play again and like!" << endl; return 0; }
24th May 2017, 1:15 AM
eiro Jan
eiro Jan - avatar
0
please make this valid
24th May 2017, 1:15 AM
eiro Jan
eiro Jan - avatar
0
make the computer more smart and pick random drops
24th May 2017, 1:16 AM
eiro Jan
eiro Jan - avatar