Add temperature convertor
This commit is contained in:
parent
8352d6f1c3
commit
ba3d3a591e
3 changed files with 34 additions and 0 deletions
|
|
@ -43,3 +43,5 @@ Interesting things to know
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
* A char is 4 bytes in Rust!
|
* A char is 4 bytes in Rust!
|
||||||
|
|
||||||
|
* Breaking with a value is only possible inside a 'loop' not a 'while/for' loop!
|
||||||
|
|
|
||||||
9
temperature_convertor/Cargo.toml
Normal file
9
temperature_convertor/Cargo.toml
Normal 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]
|
||||||
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