Help regarding Lesson 9 Tax Challenge

OK need a little help understanding this one please. I’ve pieced together what I think is right, and with the help of Xcode’s prompts I’m no longer getting any errors. The trouble is, I don’t know if it’s right because it doesn’t show the output value. Could you please give me feedback on my code? Cheers.

I’ve moved your post to it’s own thread since the thread you originally posted in has already been solved.

Apart from the fact that you have the two lines of code:

_ = 100
_ = 4

which do nothing…

The rest of your code is fine.

Although…

If you go back to the challenge, the 3 parts of the challenge work together so the 1st challenge is used in the 2nd and the 3rd challenge uses the 2nd which in turn uses the first.

ie:

//  Challenge 1
struct TaxCalculator {
    let tax = 0.13

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

//  Challenge 2
struct BillSplitter {

    let taxCalc = TaxCalculator()

    func splitBy(subtotal: Double, people: Int) -> Double {
        return taxCalc.totalWithTax(subtotal: subtotal) / Double(people)
    }
}

//  Challenge 3
let split = BillSplitter()
print(split.splitBy(subtotal: 120, people: 5))
1 Like