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 trialJeewoo Chung
609 PointsI have a 'CS1525' error that makes no sense
The error message says it's expecting "." but instead got "(" which makes no sense given the fact that every parentheses near line 15 (The error message clues that the error occurs on line 15) is correctly used and cannot be replaced by a period.
Thank you
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
while(true)
{
var answer = Console.ReadLine();
var itString = answer.GetType();
if (itString == string)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
try
{
var parsedAnswer = int.Parse(answer);
for (var i = 0; i < parsedAnswer; i++)
{
Console.WriteLine("Yay!");
}
break;
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
}
1 Answer
Steven Parker
231,269 PointsI'm not sure exactly what that error message means either, but I do see several issues that would interfere with passing the challenge:
- the input should be read only once, but the call to ReadLine is inside the outer loop
- that same loop would prevent the program from ending after issuing an error message
- I don't think you can compare anything to a keyword (like "string")
- the ReadLine function always returns a string, there's no need to test the type
- there doesn't seem to be a mechanism to detect negative inputs as asked for in the instructions
- the specific error message to issue for negative numbers does not seem to be present
I'd bet after fixing these issues that compiler error will go away.
Jeewoo Chung
609 PointsJeewoo Chung
609 PointsThank you for replying, and after going through some of your suggestions on why the code wasn't working, it worked so thank you for helping me out.