Created
April 18, 2021 07:23
-
-
Save kmbenjel/3a862cb8c99afebd486941d6acf38247 to your computer and use it in GitHub Desktop.
This program keeps accepting numbers from the user till he submits the number 0, then it prints out the sum of the numbers, the max, the min and the average and ends.
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
min = 0 | |
max = 0 | |
sum = 0 | |
count = 0 | |
input = "" | |
def results(min,max,avg) | |
puts "End of program" | |
puts "-------------------------" | |
puts "The lowest number was: #{min}" | |
puts "The highest number was: #{max}" | |
puts "The average number was: #{avg}" | |
puts "-------------------------" | |
end | |
puts "What's your name please?" | |
name = gets.chomp | |
puts "Hello " + name + "!" | |
while input != 0 | |
puts "Please type in a number!:\n" | |
input = gets.chomp.to_f | |
sum += input | |
count += 1 | |
if input < min | |
min = input | |
elsif input > max | |
max = input | |
end | |
end | |
if count == 0 | |
results("0","0","0") | |
else | |
results(min.to_s, max.to_s, (sum/count).to_s) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment