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 Final

Austin Marcoux
Austin Marcoux
835 Points

Unexpected symbol "{"

I get 2 error messages saying the compiler didn't expect "{", one on line 8 and the other on line 14. There is equally as many "{" as "}". Also, I am not getting any other error messages. Please help...

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
           Try
           {
                Console.Write("Enter the number of times to print \"Yay!\": ");
            var entry = Console.ReadLine();
            var k = int.parse(entry);
           }
            Catch(FormatException)
            {
                Console.WriteLine("This is an invalid input");
            }
            while (counter > 0)
            {
                Console.WriteLine("Yay!");
                counter = counter - 1;
            }


        }
    }
}

2 Answers

It is because you have some typos in your code, remember that C# is a capitalization sensitive language:

Try should be try
Catch should be catch
int.parse should be int.Parse

Your while loop is also not functioning, but that is a different problem you should be a able to fix yourself.

Try putting a semicolon after the catch clause:

            Catch(FormatException)
            {
                Console.WriteLine("This is an invalid input");
            };