0

Swift. Balconies. Why error Unexpectedly found nil?

func bigSquare (hei1: Int, wid1: Int, hei2: Int, wid2: Int) -> String { var balc1 = hei1 * wid1 var balc2 = hei2 * wid2 if balc1 > balc2 { return String("Apartment A") } else { return String("Apartment B") } } print(bigSquare(hei1: Int(readLine()!)!, wid1: Int(readLine()!)!, hei2: Int(readLine()!)!, wid2: Int(readLine()!)!))

24th Oct 2021, 12:13 PM
Mykyta Khlamov
2 ответов
+ 1
Thank you!
24th Oct 2021, 1:09 PM
Mykyta Khlamov
0
Mykyta Khlamov Because there are two string inputs but you are taking as four integer inputs Do this: import Foundation let apa = readLine()! let ap1 = apa.components(separatedBy: ",") let hei1 = Int(ap1[0])! let wid1 = Int(ap1[1])! let apb = readLine()! let ap2 = apb.components(separatedBy: ",") let hei2 = Int(ap2[0])! let wid2 = Int(ap2[1])! print(bigSquare(hei1: hei1, wid1: wid1, hei2: hei2, wid2: wid2))
24th Oct 2021, 12:20 PM
A͢J
A͢J - avatar