first version - needs improvement...
4 files changed, 54 insertions(+)
@@ -1,0 +1,1 @@
/target
@@ -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"
@@ -1,0 +1,6 @@
[package]
name = "temp_converter"
version = "0.1.0"
edition = "2024"
[dependencies]
@@ -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");
}
}