Programming Fundamentals/Variables/Swift

variables.swift

edit
// This program converts a Fahrenheit temperature to Celsius.
//
// References:
//     https://www.mathsisfun.com/temperature-conversion.html
//     https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html

var fahrenheit: Double
var celsius: Double

print("Enter Fahrenheit temperature:")
fahrenheit = Double(readLine()!)!

celsius = (fahrenheit - 32) * 5 / 9

print(String(fahrenheit) + "° Fahrenheit is " + String(celsius) + "° Celsius")

Try It

edit

Copy and paste the code above into one of the following free online development environments or use your own Swift compiler / interpreter / IDE.

See Also

edit