Add temperature convertor

This commit is contained in:
laurens 2020-05-02 19:13:46 +02:00
parent 8352d6f1c3
commit ba3d3a591e
3 changed files with 34 additions and 0 deletions

View file

@ -43,3 +43,5 @@ Interesting things to know
--------------------------
* A char is 4 bytes in Rust!
* Breaking with a value is only possible inside a 'loop' not a 'while/for' loop!

View file

@ -0,0 +1,9 @@
[package]
name = "temparature_convertor"
version = "0.1.0"
authors = ["laurens <miers132@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View 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);
}