DEV Community

Jack Schuster
Jack Schuster

Posted on

Trying to use the 'match' statement.

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);
Enter fullscreen mode Exit fullscreen mode

}
Regards,
Jack

Top comments (0)