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 Swift Basics (retired) Operators Binary Operators

Maikel Visser
Maikel Visser
240 Points

when 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

I 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.

let areaInMeeters = Double(area) / 10.764

Now 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

So basically when I divide things it has to be Int / Int, Double / Double, or Float / Float?

I 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
Damien Lavizzo
4,265 Points

Ninyas' solution worked like a charm for me.

I get the exact same error, and it won't work no matter the suggestions made.

Scott Graney
Scott Graney
404 Points

Thank you Ninyas Shamoel