Programming Fundamentals/Variables/Swift
Appearance
(Redirected from Computer Programming/Variables/Swift)
variables.swift
[edit | edit source]// 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 | edit source]Copy and paste the code above into one of the following free online development environments or use your own Swift compiler / interpreter / IDE.