Halloween Candy Problem (Swift) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

9th Apr 2022, 3:17 AM
R N
1 Answer
+ 1
var a:String! = readLine() var houses:Double! = Double(a) var money:Double = (2/houses!) * 100 print(Int(money.rounded(.up)))
9th Apr 2022, 6:43 AM
Simba
Simba - avatar