Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #4 Generate 3 random numbers (0-9,) ask the user to guess three numbers. Compare each
- # guess to the three random numbers. Display a message that includes the user's guess, the
- # three random numbers, and the amount of money the user has won as follows:
- # No matches: $0
- ## One match: $10
- # Two matches: $100
- ## Three matching, not in order: $1000
- # Three matching, in order: $1,000,000
- # (See page 192 for repeating digit info.)
- lottery1 = rand(10)
- lottery2 = rand(10)
- lottery3 = rand(10)
- pick1 = 10
- pick2 = 10
- pick3 = 10
- numberMatch = 0
- while pick1 >9
- puts( 'Choose your 1st lottery number. Pick a number 0-9: ')
- pick1 = gets.chomp.to_i
- end
- while pick2 >9
- puts( 'Choose your 2nd lottery number. Pick a number 0-9: ')
- pick2 = gets.chomp.to_i
- end
- while pick3 >9
- puts( 'Choose your 3rd lottery number. Pick a number 0-9: ')
- pick3 = gets.chomp.to_i
- end
- puts "You chose #{pick1}, #{pick2}, and #{pick3}."
- puts "The winning numbers are #{lottery1}, #{lottery2}, and #{lottery3}."
- if pick1 = lottery1
- numberMatch = numberMatch + 1
- end
- if pick1 = lottery2
- numberMatch = numberMatch + 1
- end
- if pick1 = lottery3
- numberMatch = numberMatch +1
- end
- if pick2 = lottery1
- numberMatch = numberMatch + 1
- end
- if pick2 = lottery2
- numberMatch = numberMatch + 1
- end
- if pick2 = lottery3
- numberMatch = numberMatch +1
- end
- if pick3 = lottery1
- numberMatch = numberMatch + 1
- end
- if pick3 = lottery2
- numberMatch = numberMatch + 1
- end
- if pick3 = lottery3
- numberMatch = numberMatch +1
- end
- if numberMatch == 0
- puts 'Your total prize money is $0.'
- elsif numberMatch == 1
- puts 'Your total prize money is $10.'
- elsif numberMatch == 2
- puts 'Your total prize money is $100.'
- elsif numberMatch == 3
- puts 'Your total prize money is $1000.'
- end
Add Comment
Please, Sign In to add comment