From f6cbf2bf76e77c8f64312f573f46cdc7bd434acd Mon Sep 17 00:00:00 2001 From: hybrid Date: Sat, 3 Oct 2026 04:40:21 +0300 Subject: add: 8 projects variables, shadowing, another_function, branches, loops, fahr2cel, fibonacci, christmax_song --- src/fahr2cel/Cargo.toml | 6 ++++++ src/fahr2cel/src/main.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/fahr2cel/Cargo.toml create mode 100644 src/fahr2cel/src/main.rs (limited to 'src/fahr2cel') diff --git a/src/fahr2cel/Cargo.toml b/src/fahr2cel/Cargo.toml new file mode 100644 index 0000000..e407553 --- /dev/null +++ b/src/fahr2cel/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "fahr2cel" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/fahr2cel/src/main.rs b/src/fahr2cel/src/main.rs new file mode 100644 index 0000000..4ea4776 --- /dev/null +++ b/src/fahr2cel/src/main.rs @@ -0,0 +1,31 @@ +use std::io; + +fn main() { + println!("Enter \"q\" to quit."); + + loop { + let mut user_input = String::new(); + + println!("Enter temperature in °F:"); + + io::stdin() + .read_line(&mut user_input) + .expect("Failed to read line."); + + if user_input.trim() == "q" { + println!("Exiting."); + break; + } + + let user_input: f64 = match user_input.trim().parse() { + Ok(num) => num, + Err(_) => continue, + }; + + println!("{user_input}°F -> °C: {:.2}", fahr2cel(user_input)); + } +} + +fn fahr2cel (fahr: f64) -> f64 { + (fahr - 32.0) * 5.0 / 9.0 +} -- cgit v1.3.1