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
Alex Parsons
Courses Plus Student 214 PointsStill having problems with Fahrenheit to Celsius conversion.
I am getting an error that reads <EXPR>:13:29: error: cannot invoke '-' with an argument list of type '(($T4), ($T8))'
var fahrenheit = 10 var celsius :Double = (5/9) * (fahrenheit - 32) <--- The error is on this line fahrenheit
I basically want to transform fahrenheit to celsius using this for swift. At this point i am not sure what i am doing wrong.
2 Answers
Stone Preston
42,016 Pointssince fahrenheit and 32 are ints, you need to cast the subtraction to a double:
var fahrenheit = 10
var celsius :Double = (5/9) * Double(fahrenheit - 32)
Alex Parsons
Courses Plus Student 214 PointsAlright this worked thanks!
Stone Preston
42,016 Pointsno problem. one way to avoid the cast would be to just to use doubles throughout your code:
var fahrenheit = 10.0
var celsius = (5.0/9.0) * (fahrenheit - 32.0)