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 trialBrandon Myles
563 PointsPasses in Workspace. Fails in Challenge.
My code below will work in my workspace and I get the exact result the challenge is looking for. I copy and paste the code into the Challenge and I get the follow:
Bummer! System.ArgumentNullException: Value cannot be null. Parameter name: String. See output for stack trace.
System.ArgumentNullException: Value cannot be null. Parameter name: String at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00054] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/number.cs:1074 at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/number.cs:745 at System.Int32.Parse (System.String s) [0x00000] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/int32.cs:120 at Treehouse.CodeChallenges.Program.Main () [0x0001f] in <473f1640fac745dd9a752ffb5b9fd241>:0 at MonoTester.Run () [0x00095] in MonoTester.cs:86 at MonoTester.Main (System.String[] args) [0x00013] in MonoTester.cs:28
What am I missing here??
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
try
{
//This will end up being the running total of how many times I say the word
double wordTotal = 0.0;
while (true)
{
string theWord = "Yay!";
//Prompt user to enter number of "Yay"
Console.Write("Enter the number of times to print \"Yay!\": ");
int numYay = Int32.Parse(Console.ReadLine());
//Prints the string "Yay" to the screen that number of times the user entered
for(int repeatYay = 0; repeatYay < numYay; repeatYay++)
{
Console.WriteLine(theWord);
}
//Need a way to get out of the program
if(numYay == 0)
{
break;
}
int timesEntered = numYay;
//Keep track of how many times the we have entered "Yay"
wordTotal += timesEntered;
Console.WriteLine(wordTotal);continue;
}
}
catch(FormatException)
{
Console.WriteLine("That is not valid input");
}
}
}
}
1 Answer
Steven Parker
231,269 PointsBe careful about testing a challenge in the workspaces.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
In this case, you have added an extra loop that prevents the program from ending if bad values are entered..
A program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.
Also, the program is not expected to print out the loop count.