This commit is contained in:
2026-04-26 11:01:23 +07:00
parent 7c5baa57fc
commit a4a8263652
3 changed files with 54 additions and 5 deletions

View File

@@ -29,3 +29,11 @@ main()

View File

@@ -1,13 +1,54 @@
/* --------------------------------------------- 100 -------------------------------------------- */ /* --------------------------------------------- 100 -------------------------------------------- */
fn tempconvert(temp :Float) { use std::io::stdin;
fn tempconvert(temp:u32, unit:String) -> (u32, String) {
if unit == "F" {
return (temp - 257, "C".to_string());
}
else if unit == "F" {
return (temp + 257, "F".to_string());
}
else {
panic!("something wrong. {unit}")
}
} }
fn main() { fn main() {
println!("Hello, world!"); println!("please input temperature unit F or C");
let mut user_input_tempunit = String::new();
match stdin().read_line(&mut user_input_tempunit) {
Ok(_) => {},
Err(_) => {
println!("something not right")
}
};
let user_input_tempunit = user_input_tempunit.trim().to_string();
println!("please input temperature");
let mut _user_input_temp = String::new();
match stdin().read_line(&mut _user_input_temp) {
Ok(_) => {},
Err(_) => {
panic!("Something went wrong");
}
};
let user_input_temp:u32 = match _user_input_temp.trim().parse::<u32>() {
Ok(num) => {num},
Err(_) => {
panic!("Something went wrong");
}
};
let converted_temp = tempconvert(user_input_temp, user_input_tempunit);
let ctemp = converted_temp.0;
let cunit = converted_temp.1;
println!("{ctemp} {cunit}");
} }