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 trialDAVID Grant
309 PointsCode compiles and run in another window, yet bombs out here with a big error code. Where's the issue?
I'm running one of your 'Finals' and it's bombing out for; System.ArgumentNullException: Value cannot be null. Parameter name: String at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) <0x7f6605fdea10 + 0x000ff> in <filename unknown>:0 at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) <0x7f6605fdd120 + 0x00094> in <filename unknown>:0 at System.Int32.Parse (System.String s) <0x7f6605fbe4a0 + 0x0001d> in <filename unknown>:0 at Treehouse.CodeChallenges.Program.Main () <0x4181dc50 + 0x00058> in <filename unknown>:0 at MonoTester.Run () [0x000d5] in /workdir/MonoTester.cs:93
The program runs in my workspaces window as requested. Program name is Test.cs.
I'd like to move on to the next section but if I'm not getting something, I'd like to be squared away first.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
while(true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string input = Console.ReadLine();
try
{
int count = int.Parse(input);
int i = 0;
while(i < count)
{
i += 1;
Console.WriteLine("Yay!");
}
}
catch(FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
}
2 Answers
Steven Parker
231,275 PointsYour expectations of the functionality differ from the challenge. Code following the challenge instructions will ask for input once, and issue either a set of "Yay" messages, or an error message, but either way it will end.
This code has an added outer loop that prevents it from ending and causes it to ask for input again.
DAVID Grant
309 PointsAhh. I read too much into it.
Thanks!
Steven Parker
231,275 PointsDAVID Grant — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!