Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sum = 0.0
- count = 0
- loop do
- puts "Enter a number and hit enter: this program will output your number, add
- it to any previous numbers, and average all numbers you've entered so
- far. Hit enter without providing a number to exit the program."
- input = gets.chomp
- break if input == ""
- input=Float(input) rescue false
- if input then
- count = count+1
- puts "You entered #{input}"
- sum = sum + input
- puts "The sum so far is #{sum}"
- average = sum / count
- puts "The average so far is #{average}"
- puts "---"
- else puts "That's not a number. Enter a valid number. "
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement