1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-12-01 22:51:45 +02:00

Add solutions to functions

This commit is contained in:
mo8it
2024-05-21 02:43:18 +02:00
parent 0f4c42d54e
commit d0b843d6c4
13 changed files with 97 additions and 41 deletions

View File

@@ -1,14 +1,14 @@
// This store is having a sale where if the price is an even number, you get 10
// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. (Don't worry
// about the function bodies themselves, we're only interested in the signatures
// for now. If anything, this is a good way to peek ahead to future exercises!)
// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
// Don't worry about the function bodies themselves, we are only interested in
// the signatures for now.
fn main() {
let original_price = 51;
println!("Your sale price is {}", sale_price(original_price));
fn is_even(num: i64) -> bool {
num % 2 == 0
}
fn sale_price(price: i32) -> {
// TODO: Fix the function signature.
fn sale_price(price: i64) -> {
if is_even(price) {
price - 10
} else {
@@ -16,6 +16,7 @@ fn sale_price(price: i32) -> {
}
}
fn is_even(num: i32) -> bool {
num % 2 == 0
fn main() {
let original_price = 51;
println!("Your sale price is {}", sale_price(original_price));
}