【发布时间】:2019-12-22 16:17:48
【问题描述】:
我已经接受了用户的输入,但是当我尝试比较时,它没有进入 if 或 else if 块。相反,它会进入 else 块
use std::io;
fn main() {
let small_coffee = 2;
let medium_coffee = 4;
let large_coffee = 6;
let mut total_price = 0;
let mut user_choice = String::new();
io::stdin().read_line(&mut user_choice).ok().expect("Eror");
if user_choice == "1" {
total_price += small_coffee;
} else if user_choice == "2" {
total_price += medium_coffee;
} else if user_choice == "3" {
total_price += large_coffee;
} else {
println!("Sorry! Invalid Choice");
}
println!("Your total bill amounted to : {}$", total_price);
}
【问题讨论】:
-
感谢兄弟抽出时间回答问题。 . .但我在 Ubuntu 18.04 上使用 VSCode 时遇到了问题
标签: rust