Added comments

This commit is contained in:
William Davis 2024-01-04 00:59:04 -05:00
parent e171cbe7dc
commit a62f2ef995
No known key found for this signature in database

View File

@ -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)),