Rust Program to Read the Height of a Person and the Print Person Is Taller, Dwarf, or Average Height Person

You are currently viewing Rust Program to Read the Height of a Person and the Print Person Is Taller, Dwarf, or Average Height Person

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

// 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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply