Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Object-Oriented Swift Inheritance Inheritance and Initializers

Can't use '-' operator on price because it is type double?

In the code in the part where I first declare discountedPrice in the superclass Product:

func discountedPrice ( percentage: Double) -> Double {
return price = price - (price * percentage / 100)
}

I get the error, cannot use '-' operator on type double. My code seems to be the same as the code in the video, can't understand why I am getting this error?

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

Looking at this function looks like there is something extra..

// Your function
func discountedPrice ( percentage: Double) -> Double {
return price = price - (price * percentage / 100)  // error
}


// The function from the video

func discountedPrice ( percentage: Double) -> Double {
return price - (price * percentage / 100)
}

Try this and see if that helps with your code, please let me know if you need help, if this answers your question please donโ€™t forget to mark is as โ€œBest Answerโ€. This helps other students identify correct answers.