From 090a365d63ce1b65dad1bf860dfd9407d7d9ff82 Mon Sep 17 00:00:00 2001 From: Pecha Date: Sun, 1 Mar 2020 16:21:22 +1000 Subject: [PATCH] update temperature version --- temperature/Cargo.lock | 2 +- temperature/Cargo.toml | 2 +- temperature/src/main.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/temperature/Cargo.lock b/temperature/Cargo.lock index 3bfe782..599596e 100644 --- a/temperature/Cargo.lock +++ b/temperature/Cargo.lock @@ -2,5 +2,5 @@ # It is not intended for manual editing. [[package]] name = "temperature" -version = "0.1.0" +version = "0.2.0" diff --git a/temperature/Cargo.toml b/temperature/Cargo.toml index c8a71a4..5a9f7e1 100644 --- a/temperature/Cargo.toml +++ b/temperature/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "temperature" -version = "0.1.0" +version = "0.2.0" authors = ["Pecha "] edition = "2018" diff --git a/temperature/src/main.rs b/temperature/src/main.rs index d86a8b8..0ad20e5 100644 --- a/temperature/src/main.rs +++ b/temperature/src/main.rs @@ -5,8 +5,8 @@ fn main() { loop { let mut scale = String::new(); let mut temperature = String::new(); - let mut o_scale = 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"); @@ -24,7 +24,13 @@ fn main() { println!("Please enter a temperature"); io::stdin().read_line(&mut temperature) .expect("ALERTA ALERTA ANTIFASCISTA"); - let mut temperature: f32 = temperature.trim().parse().unwrap(); + let mut temperature: f32 = match temperature.trim().parse() { + Ok(x) => x, + Err(_) => { + println!("Error: not recognised as a number, please try again."); + continue; + } + }; // [°C] = ([°F] - 32) x 5/9 //[°F] = [°C] x 9/5 + 32