0
Halloween Candy Problem (Swift)
var a:String! = readLine() var houses:Int! = Int(a) var money:Int = (2/houses!) * 100 print("Your chances of getting money is \(money) ") print("You visited this many houses: \(houses)") // I keep getting a 0 for the first output // How do I fix this? // I am confused on how optionals work This is the code I written up for the problem. I am stuck on how to fix this.
1 Respuesta
+ 1
var a:String! = readLine()
var houses:Double! = Double(a)
var money:Double = (2/houses!) * 100
print(Int(money.rounded(.up)))