Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Deborah Reyes
Deborah Reyes
563 Points

Compilation Failed; C# Basics Final

I keep getting this error: Program.cs(7,19): error CS1525: Unexpected symbol `)' Compilation failed: 1 error(s), 0 warnings

I'm not too sure what it's talking about because line 7 is "static void Main ()". Could anyone help me?

Program.cs
using System;

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

                try
                {
                    var numTimes = int.Parse(entry);
                    if (numTimes <=1)
                    {
                        Console.WriteLine("You must enter a positive number.");
                    }
                    while (numTimes > 0)
                    {
                        Console.WriteLine("Yay!");
                        numTimes--;
                    }
                }

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

2 Answers

Jon Wood
Jon Wood
9,884 Points

A boolean expression in the while is empty, which is causing the compilation error.

Not sure why the compiler is complaining about line 7, but the while() is wrong. You have to have something inside the (). For example, while(true) would work.