Learn Courses My Dashboard

Lesson 9 challenge , module 1

hello, I was just looking through the solution of challenge from lesson 9 module 1, i see you use the an “l” as an argument. What it is it? Funny when I google it I do not have any answer, I think it is a first local argument? can you send me link where i can learn more about it cause it wasn’t mentioned in the lesson. Thank you.

Hi @ewaperl

Welcome to the Code Crew community.

It’s not an I, it’s the digit 1. If you download the solution and open it in Xcode you will see.

This is the code copied from playground:

struct TaxCalculator {
    
    var tax = 0.15
    
    func totalWithTax(_ subtotal:Double) -> Double {
        return subtotal * (1 + tax)
    }
}

struct BillSplitter {
    
    func splitBy(subtotal:Double, numPeople:Int) -> Double {
        
        let taxCalc = TaxCalculator()
        let totalWithTax = taxCalc.totalWithTax(subtotal)
        
        return totalWithTax / Double(numPeople)  // <---- numPeople needs to be converted to a Double
    }
    
}

let split = BillSplitter()
print(split.splitBy(subtotal: 120, numPeople: 5))
1 Like

Thank you, I already did mine by myself with the same result I just do not understand why would you put there a 1

struct TaxCalculator {

var tax: Double = 0.15


func totalWithTax(price: Double) -> Double {
    return price + (price * tax)
}

}

struct BillSplitter {

func splitBy(subtotal: Double, numbOfP: Int) -> Double {
    
    let toPay = TaxCalculator()
    let total = toPay.totalWithTax(price: subtotal)
    return total/Double(numbOfP)
}

}

var tableNumberTwo = BillSplitter()

print(tableNumberTwo.splitBy(subtotal: 120, numbOfP: 5))

Thank you

Same same but different :nerd_face:
You have 3x variables in your formula (price, price, tax), but you can achieve the same result with just 2 variables (price (subtotal), tax)

1 Like

As I always say, “There is more than one way to skin a cat”.

2 Likes

There are a lots of cats, thank you for always responding vert fast. :slight_smile:

No worries. It’s afternoon here at the moment so I’m listening to the footy and having a look at some code at the same time.

1 Like