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 Unary Operators

Can someone check my Celcius to Fareinheit Extra Credit? Thanks!

//: Playground - noun: a place where people can play

import UIKit

//C x 9/5 + 32 = °F

var celcius = 1

var far = (celcius * (9/5)) + 32

Matthew Wiese
Matthew Wiese
1,659 Points

See my answer below. Cheers!

1 Answer

Matthew Wiese
Matthew Wiese
1,659 Points
var celsius = 10.0 

let fahrenheit = celsius * 1.8 + 32 

Insert any celsius temp. Make it a decimal number to show that it is a Double. If Swift does not know that Celsius is a Double then it will not convert the temp properly. If you insert 10 instead of 10.0 you will get the wrong answer. Note: The formula for conversion is a constant.

ALTERNATE VERSION (erase any previous code before using the Alternate Version)

var celsius: Double

celsius = 10 

let fahrenheit = celsius * 1.8 + 32

Explicitly declaring celsius as a Double will allow you to insert Integers instead of decimals.

Hope this helps

Thanks so much!