jeudi 1 juin 2017

Rock Paper Scissors in Ruby display winner

I'm making a rock, paper, scissors game in Ruby, and I need help with displaying a message who wins, losses or a tie. The way the program works is the program generates a random integer, called mine which is the choice the computer makes. It also gets an integer from the user, called yours, and determines if it is Paper, Rock or Scissors. The computers choice will be compared to the user’s choice then a winner is declared based on the three alternatives. So anything less than 3 will be rock, less than 6 is paper, and less than 9 is scissors.

Here is my code:

mine=(rand() * 10).to_i

#Your choice
puts 'Enter a number between zero and 9:'
yours= gets.chomp.to_i
puts

if yours<3
puts 'Your choice is Rock'


elsif
yours<6
    puts 'Your choice is Paper'

else
yours<9
    puts 'Your choice is Scissors'

 end

 #Computer choice 

 if mine<3
puts 'My choice is Rock'


 elsif
mine<6
    puts 'My choice is Paper'

 else
mine<9 
    puts 'My choice is Scissors' 
 end

  puts


  #Output 
  print 'My choice was: '
 puts  mine
 print 'Your choice was: '
puts yours 

Aucun commentaire:

Enregistrer un commentaire