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

C# C# Basics (Retired) Perform Integers

Q5 - Why won't it compite succesfully?

Why won't total =0; compile succesfully? I answered the question correct, as my intution told me it wouldn't, however I don't undertand why.

Best, Jakob

1 Answer

Raffael Dettling
Raffael Dettling
32,998 Points

The variable total has no type so it cant be assigned to an integer :)

So if it was called string total = "0" or int total = 0 it would compile? :)

Raffael Dettling
Raffael Dettling
32,998 Points

Sure it would compile one other possibility is to declare the variable before and then assign a value later

int total;

total = 0;

But remember the variable should have a vale befor using it ^^