Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialarnavthecoder
3,453 PointsErrors about structs in swift
The code is attached in the question . The error is:
swift_lint.swift:16:41: error: use of unresolved identifier 'amount'
var item = Expense(description: "Food", amount = 100)
^
Please Help Quickly!!
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String, amount: Double) {
self.description = description
self.amount = amount
}
func calculateTaxes(percentage: Double) -> Double {
return (self.amount * (percentage/100))
}
}
var item = Expense(description: "Food", amount = 100)
arnavthecoder
3,453 PointsThank You!!!!!! But I still have an error and the output does't show anything
2 Answers
Victor Levytskiy
7,608 Pointsstruct Expense {
var description: String
var amount: Double = 0.0
init (description: String, amount: Double) {
self.description = description
self.amount = amount
}
func calculateTaxes(percentage: Double) -> Double {
return (self.amount * (percentage/100))
}
}
var item = Expense(description: "Food", amount: 100)
As Ian Brennan mentioned all you need is to assign values with the : rather than =
arnavthecoder
3,453 PointsThank you all!!!
Ian Brennan
1,516 PointsIan Brennan
1,516 Pointsvar item = Expense(description: "Food", amount: 100)
Just a typo, you need to set the param with : rather than =