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

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

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

Allan Clark
Allan Clark
10,810 Points

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.");
}
Tojo Alex
Tojo Alex
Courses Plus Student 13,331 Points

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.

Allan Clark
Allan Clark
10,810 Points

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.");
            }
        }
    }
}