UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

checkpoint 1: just want to make sure my logic is correct.

Forums > 100 Days of SwiftUI

let c = 25.0
let f = Int(c) * 9 / 5 + 32
print("Celsisus: \(c)° + Fahrenheit: \(f)° "

I created a contsant for holding 25.0 the temp in celsius. I then created another contsant for holding the converted celsius to fahrenheit. Lastly printed the values respectively.

Thank you!


Welcome to HackingWithSwift forums.

+1 for formatted code!

Here are some comments I might share with a junior developer during a code review.

  1. Why do you define c as a Double, but f is in Integer ? This seems inconsistent.
  2. Consider using full words for your variables instead of c and f.
  3. Because f is an integer, you may be losing accuracy when you convert c and do maths. Are you ok with losing accuracy?
  4. Your print statement is incomplete. Missing a closing parenthesis. This may be cut/paste error.
  5. Consider replacing the + sign with an = sign in your print statement. Also, chak ur spalling.
  6. +1 for including degree symbols! Nice touch.

About variable names.

But wait, you say, c and f are common abbreviations for centigrade and fahrenheit. In this case, not a big deal. But many development teams might ask you to consider full word names for your variables. If you have a long name such as temperatureInCelsius, that's a lot to type compared with a simple "c". XCode is great in this regard, because your variables will benefit from code completion. But future you will thank past you for being more verbose. YMMV.

Keep asking questions!

Also take a few moments to read many of the older posts. There are some great nuggets in older messages.


let celsius = 25.0
let fahrenheit = celsius * 9 / 5 + 32
print("The current temperature is \(celsius)°C =  \(fahrenheit)°F.")

Thank you for the feedback! So... I removed the Int. I created two constants. One with a double, and the second using the first, using operators. Then used string interpolation to return a full sentence with correct spelling.


BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.