index : temp_converter
Convert temperature degres
about summary refs log tree commit diff

Diffstat (limited to 'src/main.rs')

-rw-r--r-- src/main.rs 40
 1 file changed, 40 insertions(+)

diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..12579a8 100644
--- /dev/null
+++ b/src/main.rs
@@ -1,0 +1,40 @@
use std::io;

fn main() {
    println!("Welcome to the temperature converter!");

    println!("Which way do you need to convert?");

    println!("Fahrenheit ---> Celsius: Press 1");

    println!("Celsius ---> Fahrenheit: Press 2");

    let mut direction = String::new(); 
    let mut start_temp = String::new(); 

    io::stdin()
        .read_line(&mut direction)
        .expect("Failed to read line.");

    let direction: u32 = direction.trim().parse().expect("Please type a number!");
    println!("You chose {direction}");

    println!("What is the starting temperature?");

    io::stdin()
        .read_line(&mut start_temp)
        .expect("Failed to read line.");

    let start_temp: f64 = start_temp.trim().parse().expect("Please type a number!");
    println!("You entered {start_temp}");
    
        if direction == 1 {
            let converted_temp: f64 = (start_temp - 32.0) / 1.8;
            println!("{start_temp}F is {converted_temp}C");
        } else if direction == 2 {
            let converted_temp: f64 = (start_temp * 1.8) + 32.0;
            println!("{start_temp}C is {converted_temp}F");
        }
}