diff --git a/7-temperature_convertion/Cargo.toml b/7-temperature_convertion/Cargo.toml new file mode 100644 index 0000000..608afd5 --- /dev/null +++ b/7-temperature_convertion/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "temperature_convertion" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/7-temperature_convertion/src/main.rs b/7-temperature_convertion/src/main.rs new file mode 100644 index 0000000..676aac5 --- /dev/null +++ b/7-temperature_convertion/src/main.rs @@ -0,0 +1,52 @@ +use std::io; +fn get_input() -> u32 + { + loop + { + let mut input = String::new(); + io::stdin() + .read_line(&mut input) + .expect("Failed to read line"); + match input.trim().parse() + { + Ok(num) => return num, + Err(_) => + { + println!("Expected Valid Number"); + } + }; + } + } +fn main() + { + println!("Hello, world!"); + + println!("1) Fahrenheit to Celsius\n2) Celsius to Fahrenheit"); + let mut selection; + let mut b = true; + while b + { + selection = get_input(); + match selection + { + 1 => + { + println!("Fahrenheit Value = ↓"); + selection = get_input(); + println!("Celsius Value = {}", (selection-32) as f32*5.0/9.0); + b = false; + }, + 2 => + { + println!("Celsius Value = ↓"); + selection = get_input(); + println!("Fahrenheit Value = {}", (selection as f32*9.0/5.0)+32.0); + b = false; + }, + _ => + { + println!("Expected Valid Value"); + }, + } + } + }