ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.