[英]How can I get the milk cost using func (Swift)
我現在正在研究 Swift 代碼,對於函數,我有一個問題。
代碼是
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))")
這個例子將返回瓶子中 milt 的總體積,給定瓶子的數量和每個瓶子的體積。
決定學習 Swift 真是太棒了!
請記住不要在代碼中使用幻數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.