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 trialDaniel Ram
Courses Plus Student 14,808 PointsC# Basics Course: Final - This doesn't seem to work for Step 2 in the Validation, but it works @ www.repl.it
This seems to work at www.repl.it but it fails in the code challenge.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
var amount = 0;
Console.Write("Enter the number of times to print \"Yay!\": ");
var input = Console.ReadLine();
if(int.TryParse(input, out amount)){
Console.WriteLine(amount);
}else{
while(true){
Console.WriteLine("You must enter a whole number");
input = Console.ReadLine();
if(int.TryParse(input, out amount)){
break;
}
}
}
for(var i = 0; i<amount; i++){
Console.Write("Yay!");
}
}
}
}
Am I doing something wrong?
1 Answer
Steven Parker
231,236 PointsIt looks like you have a couple of different issues that might cause you to fail the challenge.
For one thing, if you input a numeric value the first time, it is printed out before the words. This might throw off the automatic validation mechanism.
Also, while your use of int.TryParse is perfectly adequate for the desired behavior, the challenge included the comment "Hint: Catch the FormatException". It could be that the validation is looking specifically for a try...catch construct around a call to int.Parse in your code. Take a look at the element of this module titled "try" Code and "catch" Exceptions for examples.
You might need to fix either and maybe both of these to pass the challenge validation.
AbdiRahman Mohamed
434 PointsAbdiRahman Mohamed
434 PointsIt seems great for me!