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 trialMaikel Visser
240 Pointswhen i try to use the code let areaInMeters = area / 10.764, i get the error message stating: Binary operator '/' cannot
when i try to use the code let areaInMeters = area / 10.764, i get the error message stating: Binary operator '/' cannot be applied to operands of type 'Int and 'Double'
7 Answers
Steve Hunter
57,712 PointsI think it wants the same type of number on both sides of the division. You've got Int / Double. If you decare your area
to be a Double, this should be fine. You may be able to cast the int to a double, too.
This is down to 'strong typing' that Swift is very keen on.
I hope that helps.
Steve.
Ninyas Shamoel
812 Pointslet areaInMeeters = Double(area) / 10.764
Phil Hanson
764 PointsNow I am using El Capitan Beta and Xcode 7 Beta but what work for me is as others suggested declaring area as a double.
let areaInMeters = Double(area) / 10.764
gustavopares
Courses Plus Student 30 PointsSo basically when I divide things it has to be Int / Int, Double / Double, or Float / Float?
Steve Hunter
57,712 PointsI think you need to think further than that. You need to think about what is receiving the result too - Int /Int may need the receiver to be expecting a Float as the result is relatively unlikely to be an Int unless we're losing loads of accuracy.
Damien Lavizzo
4,265 PointsNinyas' solution worked like a charm for me.
reesesherman
507 PointsI get the exact same error, and it won't work no matter the suggestions made.
Scott Graney
404 PointsThank you Ninyas Shamoel