You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
658 B

// functions4.rs
3 years ago
// 让我能够编译!执行 `rustex hint functions4` 获取提示 :)
3 years ago
// 商店正在进行促销,如果价格是偶数,可以优惠 10 Rustbucks如果是奇数则优惠 3 Rustbucks。
// 译Rustbucks 可能想表达 Rust元 的意思,好比 美元 。
// I AM NOT DONE
3 years ago
/// 翻译: [mg-chao](https://github.com/mg-chao)
fn main() {
let original_price = 51;
3 years ago
println!("Your sale price is {}", sale_price(original_price));// 译:"你需支付 {}"
}
fn sale_price(price: i32) -> {
if is_even(price) {
price - 10
} else {
price - 3
}
}
fn is_even(num: i32) -> bool {
num % 2 == 0
}