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 »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.