lundi 20 janvier 2020

How can I use an if statement to check if what the user entered is a specific value? [duplicate]

I wrote the following code to check if the user entered "Hi" and in that case it would print "Bye", but every time I run the program it just prints "Hi".

use std::io;

fn main() {
    let mut input = String::new();
    println!("Say something:");
    match io::stdin().read_line(&mut input) {
        Ok(_) => {}
        Err(e) => println!("Error: {}", e),
    };
    if input == "Hi" {
        println!("Bye");
    }
}

Aucun commentaire:

Enregistrer un commentaire