Novice in Swift and I'm having a frustrating problem. The program compiles correctly and runs without crashing. The program is supposed to calculate the age of a cat in cat years based user-inputted human years. After pressing the button, however, the result is diplayed with the word "Operator" appended by the cat years which is delimited by parenthesis, i.e., Optional(35). Here is my code:
@IBOutlet weak var getHumanYears: UITextField!
@IBOutlet weak var displayCatYears: UILabel!
@IBAction func calculateCatYears(_ sender: Any)
{
if let humanYears = getHumanYears.text
{
var catYears: Int? = Int(humanYears)
catYears = catYears! * 7
let catYearsString: String = String(describing: catYears)
displayCatYears.text = "Your cat is " + catYearsString + " years old"
}
}
Does anyone know what I'm doing wrong? Thank you for your valuable input!
