Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @prices = []
- @num_of_items = 0
- @sum = 0
- puts "Enter the amount of money you have:"
- print "$"
- @amount_of_money = gets.chomp.to_i
- puts "Enter the number of items:"
- @num_of_items = gets.chomp.to_i
- while @prices.length <= (@num_of_items - 1)
- puts "Enter item #{@prices.length+1} price:"
- print "$"
- @prices << gets.chomp
- break if @prices.last == -1
- end
- puts "*" * 50
- @prices.each do |p|
- @sum += p.to_i
- end
- puts "You have a total of $#{@sum}."
- if @sum >= @amount_of_money
- short = (@amount_of_money-@sum).abs
- puts "You have enough money by $ #{short}. Now go buy it!"
- exit
- end
- if @sum < @amount_of_money
- diff = (@sum-@amount_of_money).abs
- puts "Sorry, you don't have enough money. You are short by $#{diff}."
- exit
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement