Add a program for converting temperature
This commit is contained in:
parent
852f5a9b76
commit
c6e001b549
3 changed files with 43 additions and 0 deletions
7
hottie/Cargo.lock
generated
Normal file
7
hottie/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hottie"
|
||||||
|
version = "0.1.0"
|
6
hottie/Cargo.toml
Normal file
6
hottie/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "hottie"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
30
hottie/src/main.rs
Normal file
30
hottie/src/main.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut input = String::new();
|
||||||
|
let celsius: bool = {
|
||||||
|
loop {
|
||||||
|
println!("Please enter the unit you wish to convert from:");
|
||||||
|
println!("0: Celsius");
|
||||||
|
println!("1: Fahrenheit");
|
||||||
|
io::stdin().read_line(&mut input).expect("An error occurred!");
|
||||||
|
|
||||||
|
break match input.trim().parse::<i32>() {
|
||||||
|
Err(_) => {
|
||||||
|
println!("The specified input `{}` is invalid.", input.trim());
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
Ok(value) => {
|
||||||
|
value == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
println!("Please enter the value to convert:");
|
||||||
|
io::stdin().read_line(&mut input).expect("An error occurred!");
|
||||||
|
let value: f64 = input.trim().parse().unwrap();
|
||||||
|
|
||||||
|
println!("result: {}", if celsius { value * 9.0 / 5.0 + 32.0 } else { (value - 32.0) * 5.0 / 9.0 })
|
||||||
|
}
|
Loading…
Reference in a new issue