# sample Ruby code to count vowels in input # this uses just basic Ruby operations def vowels_in_line(text) # downcase all letters, leaving the result in text text.downcase! # this could be written using a for loop, but that requires ranges vowels = 0 i = 0 while i < text.size ch = text[i] if ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' vowels += 1 end i += 1 end return vowels end def main print "Enter lines of text, marking end-of-input with Control-Z on Windows " puts "and Control-D on OSX:" total_vowels = 0 input_line = gets while input_line total_vowels += vowels_in_line(input_line) input_line = gets end puts "Number of vowels in input: #{total_vowels}" end main