This content originally appeared on DEV Community and was authored by Jack Schuster
Below is my code:
I am trying to have a default error message but rust does not like it. The match variable is i32 how can I send a default message?
Any suggestions would be most helpful.
Error is on line 16.
fn main() {
println!("Please select the conversion type:");
println!("1. Fahrenheit to Celsius");
println!("2. Celsius to Fahrenheit");
let mut conversion_type = String::new();
io::stdin().read_line(&mut conversion_type)
.expect("Failed to read line");
let conversion_type = conversion_type.trim();
let conversion_type = match conversion_type {
"1" => 1,
"2" => 2,
"3" => 3,
_ => { println!("Please input 1 or 2!")} //gives error in rust
};
println!("The converted temperature is {}", conversion_type);
}
Regards,
Jack
This content originally appeared on DEV Community and was authored by Jack Schuster
Jack Schuster | Sciencx (2025-01-11T20:50:39+00:00) Trying to use the ‘match’ statement.. Retrieved from https://www.scien.cx/2025/01/11/trying-to-use-the-match-statement/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.