29 lines
785 B
Rust
29 lines
785 B
Rust
|
use std::{
|
||
|
io::{self, Write},
|
||
|
num::ParseFloatError,
|
||
|
};
|
||
|
|
||
|
use day43::tri_area;
|
||
|
|
||
|
fn read_f64(request: &str) -> Result<f64, ParseFloatError> {
|
||
|
let mut input = String::new();
|
||
|
print!("{}", request);
|
||
|
io::stdout().flush().expect("Failed to flush stdout");
|
||
|
std::io::stdin()
|
||
|
.read_line(&mut input)
|
||
|
.expect("Failed to read input");
|
||
|
input.trim().parse()
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let base = read_f64("Enter the base of the triangle: ");
|
||
|
let height = read_f64("Enter the height of the triangle: ");
|
||
|
match base {
|
||
|
Ok(base) => match height {
|
||
|
Ok(height) => println!("The area of the triangle is: {}", tri_area(base, height)),
|
||
|
Err(e) => println!("Error: {}", e),
|
||
|
},
|
||
|
Err(e) => println!("Error: {}", e),
|
||
|
}
|
||
|
}
|