I\'m trying to write this code in Ruby for a program I\'m trying to run, but I\'
ID: 3927154 • Letter: I
Question
I'm trying to write this code in Ruby for a program I'm trying to run, but I'm having trouble getting it to execute properly.
There are different messages that will appear, depending in the value input.
Too Hot for Me
A bit Warm
And so on.
I'm trying to enter so that it generates this:
Trying to enter 40 does not generate a message, it just gives the temperature in Celsius.
Please make the necessary changes to the program so the entry of 40 will generate the following output posted above.
Here's the code I currently have, but is erroing out:
puts 'give me the temperature'
temp1=gets
temp2=temp1.to_f
puts 'Here is your temperature in Celsius: '
puts (tem1p-32)*0.5556
if temp1>99
puts 'Too Hot for Me!'
exit
end
if temp1>80
puts 'A Bit Warm'
exit
end
if temp1>70
puts 'It's really nice'
exit
end
if temp1>40
puts 'A little Cool'
exit
end
if temp1<40
puts 'Too cold...Bye'
exit
end
Explanation / Answer
//Tested on Online Ruby Compiler
/**********program**********/
puts 'give me the temperature'
temp1=gets.to_i # taking input as integer
temp2=temp1.to_f
puts 'Here is your temperature in Celsius: '
puts (temp1-32)*0.5556
if temp1>99
puts 'Too Hot for Me!'
exit
end
if temp1>80
puts 'A Bit Warm'
exit
end
if temp1>70
puts 'It's really nice'
exit
end
if temp1>40
puts 'A little Cool'
exit
end
if temp1<=40
puts 'Too cold...Bye'
exit
end
/***********output*********/
give me the temperature
40
Here is your temperature in Celsius:
4.4448
Too cold...Bye
sh-4.3$ ruby main.rb
give me the temperature
81
Here is your temperature in Celsius:
27.2244
A Bit Warm
sh-4.3$ ruby main.rb
give me the temperature
75
Here is your temperature in Celsius:
23.8908
It's really nice
Thanks a lot
If you have any query Please feel free to ask