Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Enums and Structs Structs Review Structs

im a bit confused in this simple question

I know it should be easy but im not getting it for some reason

struct.swift
struct Expense {
    var description: String
    var amount: Double 
  var amount: "0.0"
}

1 Answer

Michael Pastran
Michael Pastran
4,727 Points

this is how your code should look

struct Expense {

var description: String
var amount : Double = 0.0

}

The reason why your getting an error is for two reasons. the first is that you are creating another variable called "amount" so in your code you have two variables named "amount" in the future if you want to change the value of a variable that has already been declared you just need to call the variable and then assign it the new value. soooo " amount = 0.0 " not "var amount = "0.0" " because then you are creating a second variable. then the second error your making is that when you are passing it a value, you are using "0.0 " , you only use the " " when passing it a string. numbers don't need " ". let me know if it helped.