rust-book/ftoc/src/main.rs
Timothy Warren 861134542a First commit
2019-01-30 14:25:30 -05:00

23 lines
496 B
Rust

use std::io;
fn main() {
println!("Fahrenheit to Celsius Converter");
println!("Enter temperature in Fahrenheit");
let mut temp = String::new();
io::stdin().read_line(&mut temp)
.expect("Failed to read line");
let input_temp: f64 = temp.trim().parse()
.expect("Input must be a number");
let converted = f_to_c(input_temp);
println!("{}°F is {}°C", input_temp, converted);
}
fn f_to_c(fahrenheit: f64) -> f64 {
(fahrenheit - 32.0) / 1.8
}