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

What did I do wrong now

I don't know what i did wrong these error's keep on coming: Program.cs(20,38): error CS1525: Unexpected symbol (', expecting)' or identifier' Program.cs(20,73): error CS1525: Unexpected symbol)' Compilation failed: 2 error(s), 0 warnings

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            try{
            Console.Write("Enter the number of times to print \"Yay!\": ");
            string input = Console.ReadLine();

            int count = int.Parse(input);

            int i = 0;
            while(i < count)
            {
                i += 1;   
                Console.WriteLine("Yay!");
            }

            } catch (Console.WriteLine("You must enter a whole number.");)    
        }
    }
}

2 Answers

Inside the parenthesis of the catch should be the Exception the block is trying to catch. Then you need brackets to tell it what to do when that exception is caught. Try this.

} catch(FormatException e) {

       Console.WriteLine("You must enter a whole number.");
}

thanks i only have one problem now and its where i'm placing the { } brackets if you could show your code then i can see what is wrong with my brackets.

no problem

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            try{
                 Console.Write("Enter the number of times to print \"Yay!\": ");
                 string input = Console.ReadLine();

                 int count = int.Parse(input);

                 int i = 0;
                 while(i < count)
                 {
                     i += 1;   
                     Console.WriteLine("Yay!");
                 }

            } catch(FormatException e) {

                 Console.WriteLine("You must enter a whole number.");
            }
        }
    }
}

thanks