I'm studying the Swift code now, and for the func, I have a question.
The code is
func getMilk(bottles: Int) {
var cost = bottles * 1.5
print("Milk cost is $\(cost)")
}
getMilk(bottles: 4)
I'm studying the Swift code now, and for the func, I have a question.
The code is
func getMilk(bottles: Int) {
var cost = bottles * 1.5
print("Milk cost is $\(cost)")
}
getMilk(bottles: 4)
func getMilk(numberOfBottles: Int,
bottleVolume: Float) -> Float {
var cost = Float(numberOfBottles) * bottleVolume
return cost
}
print("Milk func return: \(getMilk(bottles: 5, bottleVolume: 1.5))")
This example will return the total volume of milt in bottles, given the number of bottles and each bottle's volume.
Great job on deciding to learn Swift!
Please remember not to use magic numbers in your code.