-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw1C2.rb
30 lines (24 loc) · 791 Bytes
/
w1C2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def convert_temp(input)
type = input.slice(-1).upcase
temp = input.slice(0..-2).to_f
case type
when "F"
puts "#{input} converts to #{fahrenheit(temp)}."
when "C"
puts "#{input} converts to #{celsius(temp)}."
else
puts "Please enter a temperature in the proper format."
end
end
def fahrenheit(temp)
"#{format("%.2f", (temp-32) * 5.0 / 9)} celsius"
end
def celsius(temp)
"#{format("%.2f", temp * 9.0 / 5 + 32)} fahrenheit"
end
puts "This is a temperature conversion application. It converts Farenheit to Celsius, and Celsius to Farenheit"
puts "To convert Farenheit to Celsius, format your input like 32F"
puts "To convert Celsius to Farenheit, format your input like 0C"
puts "Enter the temperature you want to convert"
temp = gets.chomp
convert_temp(temp)