Add temperature convertor
This commit is contained in:
parent
8352d6f1c3
commit
ba3d3a591e
3 changed files with 34 additions and 0 deletions
23
temperature_convertor/src/main.rs
Normal file
23
temperature_convertor/src/main.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::io;
|
||||
use std::process::exit;
|
||||
|
||||
fn main() {
|
||||
let mut fahr = String::new();
|
||||
|
||||
println!("Input fahrenheit number:");
|
||||
io::stdin().read_line(&mut fahr).expect("Failed to read user input");
|
||||
|
||||
// let fahr: f64 = fahr.trim().parse().expect("Not a number!");
|
||||
let fahr: f64 = match fahr.trim().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => {
|
||||
println!("Can't work with that!");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let celsius = (fahr - 32.0) / 1.8;
|
||||
|
||||
println!("{} Fahrenheit is {} in Degrees Celsius", fahr, celsius);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue