ADVERTISEMENT
ADVERTISEMENT

Rust program to read the height of a person and the print person is taller, dwarf, or average height person

Given the height of a person, and the print person is taller, dwarf, or average height person using the Rust program.
Submitted by Nidhi, on October 02, 2021

Problem Solution:

Here, we will read the height from the person in centimetres and the print person is a 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.

// Rust program to read the height of a person 
// and the print person is taller, dwarf, 
// or average height person

use std::io;

fn main() 
{
    let mut height:f32=0.0;
    
    let mut input = String::new();
    
    println!("Enter Height (in centimetres):");
    io::stdin().read_line(&mut input).expect("Not a valid string");
    height = input.trim().parse().expect("Not a valid number");
    
    if height >= 150.0 && height <= 170.0 
    {
        println!("Person is average height person");
    }
    else if height > 170.0 && height <= 195.0
    {
        println!("Person is taller");
    }
    else if height < 150.0 
    {
        println!("Person is dwarf");
    }
    else
    {
        println!("Abnormal height");
    }  
}

Output:

Enter Height (in centimetres):
187
Person is taller

Explanation:

Here, we read the height of the person in centimetres from the user. After that, we printed the appropriate message.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


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.