Average word length problem.
Hi, myself varun (clearly written on id but i like an intro). So, i am stuck in the average word length code coach, for 2 days. I tried every relevant way of trying but didnt Succeeded. (I am using ruby) The only problem is every time I round the numbers to floor() they last 4 cases are wrong and when i use ceil() the 1st case is wrong. So my code is below :- strings = gets.chomp.to_s letter = strings.split("") letter.delete(" ") word = strings.split(" ") letters = letter.size().to_f words = word.size().to_f average = (letters / words) num1 = average.round(1) num2 = average.to_i log = num1 - num2 x = 0.5 if log <= 0.5 print average.ceil() else print average.floor() end I used round also but wasnt helpful. Please give me some ideas as answers as i am stuck and please try providing answers in Ruby. For further Inquiries you can DM me i would like to have a solution. ☺ Thanks in advance.