removed binary and added whole temperature directory

This commit is contained in:
Pecha 2019-10-13 13:23:04 +10:00
parent e1f0c9faad
commit f830d83b92
5 changed files with 55 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/*/target
**/*.rs.bk

Binary file not shown.

6
temperature/Cargo.lock generated Normal file
View File

@ -0,0 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "temperature"
version = "0.1.0"

9
temperature/Cargo.toml Normal file
View File

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

38
temperature/src/main.rs Normal file
View File

@ -0,0 +1,38 @@
use std::io;
fn main() {
println!("Welcome to Pecha's Temperature Converter! 0u0!");
loop {
let mut scale = String::new();
let mut temperature = String::new();
let mut o_scale = String::new();
println!("Please enter a scale to convert from- Farenheit (F) or Celsius (C)");
io::stdin().read_line(&mut scale)
.expect("ALERTA ALERTA ANTIFASCISTA");
scale = scale.trim().to_string();
if scale != "F" && scale != "C" {
println!("No recognised scale, please try again");
continue;
}
o_scale = o_scale.trim().to_string();
if scale == "F" {o_scale = "C".to_string();}
if scale == "C" {o_scale = "F".to_string();}
println!("Please enter a temperature");
io::stdin().read_line(&mut temperature)
.expect("ALERTA ALERTA ANTIFASCISTA");
let mut temperature: f32 = temperature.trim().parse().unwrap();
// [°C] = ([°F] - 32) x 5/9
//[°F] = [°C] x 9/5 + 32
if scale == "F" {
temperature = (temperature - 32.0)*5.0/9.0;
} else {
temperature = (temperature*9.0/5.0)+32.0;
}
println!("Your new temperature is {} degrees °{}",temperature,o_scale)
}
}