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 trialAntoine Guenet
2,843 PointsMultiply an Int with a Double
I was happy to pass this final exam on Object Oriented Swift but I pretended my constant "sides" was of type "String". I see the teacher didn't encounter any problem because his calculation in the getter is sideLength * sideLength (Double). But I wanted to try with sideLength * sides (Double * Int). Obviously I get an error because I can't multiply a Double by an Int. But what would be the workaround ?
2 Answers
nicoschuele
3,713 PointsConvert your Int to a Double using the Double()
method. Example:
let a = 3.0
let b = 2
let c = a * Double(b) // outputs 6.0
let d = Int(c) // converts back your result to an Int if needed
Antoine Guenet
2,843 PointsGreat! Thanks :-)
nicoschuele
3,713 PointsPas de soucis ;-)