Skip to content

Instantly share code, notes, and snippets.

@tombasche
Created September 15, 2018 12:03
Show Gist options
  • Save tombasche/66bca38473bf5746c53b7d0f724b9f7a to your computer and use it in GitHub Desktop.
Save tombasche/66bca38473bf5746c53b7d0f724b9f7a to your computer and use it in GitHub Desktop.
Fahrenheit to celsius
// 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