mirror of
https://codeberg.org/unbeatable-101/FahrenheitToCelsius.git
synced 2024-06-19 07:17:09 +00:00
Added comments
This commit is contained in:
parent
e171cbe7dc
commit
a62f2ef995
|
@ -10,6 +10,7 @@ fn convert_to_c(temp: f32) -> f32 {
|
|||
}
|
||||
|
||||
fn convert_to_f(temp: f32) -> f32 {
|
||||
//Defining what 5/9 is, then deviding the input by it and adding 32
|
||||
const FIVE_DIV_NINE: f32 = 5.0 / 9.0;
|
||||
let mut fahrenheit = temp / FIVE_DIV_NINE;
|
||||
fahrenheit += 32_f32;
|
||||
|
@ -27,11 +28,16 @@ fn main() {
|
|||
.read_line(&mut input)
|
||||
.expect("Failed to read line");
|
||||
let input = input.trim();
|
||||
//Split the input into to strings, input: Contains the number
|
||||
//and system: Contains if it is celcius or fahrenheit
|
||||
let (input,system) = input.split_at(input.len() - 1);
|
||||
//If the input in a number, output it, else, restart loop
|
||||
let input: f32 = match input.parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
//If the system is know, call the convert function, else,
|
||||
//repeat loop
|
||||
match system {
|
||||
"C" => println!("{}°C is {:.2}°F", input, convert_to_f(input)),
|
||||
"F" => println!("{}°F is {:.2}°C", input, convert_to_c(input)),
|
||||
|
|
Loading…
Reference in New Issue
Block a user