Skip to content

Instantly share code, notes, and snippets.

@jmbuscemi
Created May 5, 2015 03:53
Show Gist options
  • Save jmbuscemi/3161e1406239d0c4c600 to your computer and use it in GitHub Desktop.
Save jmbuscemi/3161e1406239d0c4c600 to your computer and use it in GitHub Desktop.
User input tracker
continue = true
count = 0
sum = 0
while continue
puts "Enter your number: "
answer = gets.chomp
if answer == ""
puts "Goodbye!"
continue = false
elsif (answer.to_i.to_s != answer) && (answer.to_f.to_s != answer)
puts "Input needs to be a number!"
else
sum += answer.to_f
count +=1
end
end
average = sum / count
puts "The sum of your numbers is #{sum} and the average is #{average}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment