#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Need help with a Rock/Paper/Scissors program


    Heyo! I am new to the forums and new to Ruby. One of the first things that I did was create a Rock,
    Paper, and Scissors game. There is an error somewhere in the game where the computerwins, player-
    wins, and the ties are not being added to. The gamesplayed is working but the others aren't. Here is
    the program, any help is appreciated: (please note that the long line of dashes it just to separate the matches in the terminal, and there is some pseudocode still in the program as I am not organized, thanks!)



    #prompt for username
    puts "Please enter a Username:"
    username = gets.chomp
    puts "Your username is: #{username}"
    gamesplayed = 0
    playerwins = 0
    computerwins = 0
    tie = 0
    my_array2 = ["Good Job","Great!"]
    begin
    puts "-----------------------------------------------------"
    puts "Enter Rock, Paper, or Scissors."
    my_array = ["rock","paper","scissors"]
    computer_choice = my_array[rand(3)]
    gamesplayed = gamesplayed + 1
    #Player inputs choice
    user_choice = gets.chomp
    #ROCK
    #Player chooses rock, computer chooses rock.
    #Tie
    if (user_choice == "rock") && (computer_choice == "rock")
    puts "Tie"
    tie = tie + 1
    #Player chooses rock, computer chooses paper.
    #Computer wins
    elsif (user_choice == "rock") && (computer_choice == "paper")
    puts "Computer Wins"
    computerwins = computerwins + 1
    #Player chooses rock, computer chooses scissors.
    #Player wins
    elsif (user_choice == "rock") && (computer_choice == "scissors")
    puts "User Wins"
    playerwins = playerwins + 1
    #PAPER
    #Player chooses paper, computer chooses paper.
    #Tie
    elsif (user_choice == "paper") && (computer_choice == "paper")
    puts "Tie"
    tie = tie + 1
    #Player chooses paper, computer chooses rock.
    #Player wins
    elsif (user_choice == "paper") && (computer_choice == "rock")
    puts "User Wins"
    playerwins = playerwins + 1
    #Player chooses paper, computer chooses scissors.
    #Computer wins
    elsif (user_choice == "paper") && (computer_choice == "scissors")
    puts "Computer Wins"
    computerwins = computerwins + 1
    #SCISSORS
    #Player chooses scissors, computer chooses scissors.
    #Tie
    elsif (user_choice == "scissors") && (computer_choice == "scissors")
    puts "Tie"
    tie = tie + 1
    #Player chooses scissors, computer chooses paper.
    #Player wins
    elsif (user_choice == "scissors") && (computer_choice == "paper")
    puts "User Wins"
    playerwins = playerwins + 1
    #Player chooses scissors, computer chooses rock.
    #Computer wins
    elsif (user_choice == "scissors") && (computer_choice == "rock")
    puts "Computer Wins"
    computerwins = computerwins + 1

    end
    puts "#{my_array2[rand(2)]}"


    puts gamesplayed
    puts computerwins
    puts playerwins
    puts tie


    end while gamesplayed < 3
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0
    Also, there is a problem with the random array for the computer_choice. Where did I go wrong there? Thanks!
  4. #3
  5. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,113
    Rep Power
    2010
    Please use code tags for you code.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0
    Okay. I don't see anything that allows me to edit. Sorry for not using tags.

IMN logo majestic logo threadwatch logo seochat tools logo