Guest User

Untitled

a guest
Aug 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #4 Generate 3 random numbers (0-9,) ask the user to guess three numbers. Compare each
  2. # guess to the three random numbers. Display a message that includes the user's guess, the
  3. # three random numbers, and the amount of money the user has won as follows:
  4. # No matches: $0
  5. ## One match: $10
  6. # Two matches: $100
  7. ## Three matching, not in order: $1000
  8. # Three matching, in order: $1,000,000
  9. # (See page 192 for repeating digit info.)
  10.  
  11. lottery1 = rand(10)
  12. lottery2 = rand(10)
  13. lottery3 = rand(10)
  14.  
  15. pick1 = 10
  16. pick2 = 10
  17. pick3 = 10
  18.  
  19. numberMatch = 0
  20.  
  21. while pick1 >9
  22. puts( 'Choose your 1st lottery number. Pick a number 0-9: ')
  23. pick1 = gets.chomp.to_i
  24. end
  25.  
  26. while pick2 >9
  27. puts( 'Choose your 2nd lottery number. Pick a number 0-9: ')
  28. pick2 = gets.chomp.to_i
  29. end
  30.  
  31. while pick3 >9
  32. puts( 'Choose your 3rd lottery number. Pick a number 0-9: ')
  33. pick3 = gets.chomp.to_i
  34. end
  35.  
  36. puts "You chose #{pick1}, #{pick2}, and #{pick3}."
  37. puts "The winning numbers are #{lottery1}, #{lottery2}, and #{lottery3}."
  38.  
  39. if pick1 = lottery1
  40. numberMatch = numberMatch + 1
  41. end
  42.  
  43. if pick1 = lottery2
  44. numberMatch = numberMatch + 1
  45. end
  46.  
  47. if pick1 = lottery3
  48. numberMatch = numberMatch +1
  49. end
  50.  
  51. if pick2 = lottery1
  52. numberMatch = numberMatch + 1
  53. end
  54.  
  55. if pick2 = lottery2
  56. numberMatch = numberMatch + 1
  57. end
  58.  
  59. if pick2 = lottery3
  60. numberMatch = numberMatch +1
  61. end
  62.  
  63. if pick3 = lottery1
  64. numberMatch = numberMatch + 1
  65. end
  66.  
  67. if pick3 = lottery2
  68. numberMatch = numberMatch + 1
  69. end
  70.  
  71. if pick3 = lottery3
  72. numberMatch = numberMatch +1
  73. end
  74.  
  75. if numberMatch == 0
  76. puts 'Your total prize money is $0.'
  77. elsif numberMatch == 1
  78. puts 'Your total prize money is $10.'
  79. elsif numberMatch == 2
  80. puts 'Your total prize money is $100.'
  81. elsif numberMatch == 3
  82. puts 'Your total prize money is $1000.'
  83. end
Add Comment
Please, Sign In to add comment