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) Perfect Doubles

This is not valid input

Hello,

I did everything on my Visual Studio but I still get a "this is not valid input" when I enter "20 5" minutes in the console. I replaced all the int by double but still got this error.

Screenshots : http://1drv.ms/247Rhg6 http://1drv.ms/1LrJwGs

Thank you

4 Answers

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi Mika it might be because of your input of "2 05" instead of "205". If there is a space between the numbers, it won't allow you to parse it to either double or int.

            // Works fine
            string s = "205";
            double d = double.Parse(s);

            // Throws an error
            s = "2 05";
            d = double.Parse(s);

Actually I wrote 20.5 like in the course. After your post I tried "," and it worked. Is it because my keyboard is a french one ? This is weird.

Thanks for your help !

I think it's the space. I've haven't learned yet if spaces are parsed with C#, but Rune (above) says no.

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

C# write and understand decimal in the language of the OS... Your culture is surely french or another culture where the decimal character is "," and not "."