WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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!

1      

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.

2      

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.

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

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

Reply to this topic…

You need to create an account or log in to reply.

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.