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.

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,997 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,997 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 ^^