diff options
| author | mo8it <mo8it@proton.me> | 2024-05-21 02:43:18 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-05-21 02:43:18 +0200 |
| commit | d0b843d6c4a99636d3dc6caf3ceebea14cb3b07d (patch) | |
| tree | 2021b096bdd07d37abbf71ed1df3b0b58753f67a /exercises/02_functions/functions4.rs | |
| parent | 0f4c42d54ea7322a4ee0ae7036c058c3061e80e9 (diff) | |
Add solutions to functions
Diffstat (limited to 'exercises/02_functions/functions4.rs')
| -rw-r--r-- | exercises/02_functions/functions4.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/exercises/02_functions/functions4.rs b/exercises/02_functions/functions4.rs index 06d3b1b..b22bffd 100644 --- a/exercises/02_functions/functions4.rs +++ b/exercises/02_functions/functions4.rs @@ -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)); } |
