rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

functions4.rs (570B)


      1 // This store is having a sale where if the price is an even number, you get 10
      2 // Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
      3 // Don't worry about the function bodies themselves, we are only interested in
      4 // the signatures for now.
      5 
      6 fn is_even(num: i64) -> bool {
      7     num % 2 == 0
      8 }
      9 
     10 // TODO: Fix the function signature.
     11 fn sale_price(price: i64) -> i64 {
     12     if is_even(price) {
     13         price - 10
     14     } else {
     15         price - 3
     16     }
     17 }
     18 
     19 fn main() {
     20     let original_price = 51;
     21     println!("Your sale price is {}", sale_price(original_price));
     22 }