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 trial

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.