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.
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.
Output:
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