100-days-of-rust/Week-01/Day-01_Convert-Ages-To-Days/convert_ages_to_days/src/main.rs
2024-07-26 16:03:54 +02:00

23 lines
573 B
Rust

use std::io::{self, Write};
fn calc_age(age: u16) -> u16 {
const DAYS_IN_YEAR: u16 = 365;
return age * DAYS_IN_YEAR;
}
fn main() {
print!("Write your age: ");
io::stdout().flush().expect("Failed to flush stdout.");
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("Error while trying to read from stdin.");
let age: u16 = buffer.trim().parse()
.expect("The input is not an integer between 0 and 65535");
let days = calc_age(age);
println!("Your age is about {} days", days);
}