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

Diffstat

-rw-r--r-- .gitignore 1
-rw-r--r-- Cargo.lock 7
-rw-r--r-- Cargo.toml 6
-rw-r--r-- src/main.rs 40
 4 files changed, 54 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf 100644
--- /dev/null
+++ b/.gitignore
@@ -1,0 +1,1 @@
/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..f7f7150 100644
--- /dev/null
+++ b/Cargo.lock
@@ -1,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "temp_converter"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..b64490b 100644
--- /dev/null
+++ b/Cargo.toml
@@ -1,0 +1,6 @@
[package]
name = "temp_converter"
version = "0.1.0"
edition = "2024"

[dependencies]
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");
        }
}