Created
May 5, 2015 03:53
-
-
Save jmbuscemi/3161e1406239d0c4c600 to your computer and use it in GitHub Desktop.
User input tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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