Q:

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

belongs to collection: Rust Basic Programs

0

Here, we will read the height from the person in centimetres and the print person is a taller, dwarf, or average height person.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to create own Power function without ... >>
<< Rust program to extract the last two digits from a...