update
This commit is contained in:
0
temperature_converter/rust_version/README.md
Normal file
0
temperature_converter/rust_version/README.md
Normal file
@@ -1,13 +1,54 @@
|
||||
|
||||
/* --------------------------------------------- 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() {
|
||||
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}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user