Created
September 15, 2018 12:03
-
-
Save tombasche/66bca38473bf5746c53b7d0f724b9f7a to your computer and use it in GitHub Desktop.
Fahrenheit to celsius
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fahrenheit to Celsius | |
// (F - 32) * (5/9) = C | |
use std::io; | |
fn main() { | |
let mut input = String::new(); | |
io::stdin().read_line(&mut input).unwrap(); | |
let trimmed = input.trim(); | |
let trimmed = match trimmed.parse::<f32>() { | |
Ok(i) => i, | |
Err(..) => panic!("Not a number"), | |
}; | |
let trimmed = fahrenheit_to_celsius(trimmed); | |
println!{"{}", trimmed.to_string()}; | |
} | |
fn fahrenheit_to_celsius(f: f32) -> f32 { | |
(f - 32.0_f32) * (5.0_f32/9.0_f32) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment