Home »
Ruby »
Ruby Programs
Ruby program to read the height of a person and the print person is taller, dwarf, or average height person
Ruby Example: Write a program to read the height of a person and the print person is taller, dwarf, or average height person.
Submitted by Nidhi, on November 30, 2021
Problem Solution:
In this program, we will read the height of a person from the user. Then we will print person taller, dwarf, or average height person.
Program/Source Code:
The source code to read the height of a person and the print person is taller, dwarf or average height person is given below. The given program is compiled and executed successfully.
# Ruby program to read the height of a person
# and the print person is taller, dwarf,
# or average height person
print "Enter height: ";
height = gets.chomp.to_f;
if height >= 150.0 && height <= 170.0
print "Person is average height person";
elsif height > 170.0 && height <= 195.0
print "Person is taller";
elsif height < 150.0
print "Person is dwarf";
else
print "Abnormal height";
end
Output:
Enter height: 186.2
Person is taller
Explanation:
In the above program, we read the height of a person from the user. Then we check the height of the person and printed the appropriate message based on input height that person is taller, dwarf, or average height person.
Ruby Basic Programs »