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

Tomasz Necek
PLUS
Tomasz Necek
Courses Plus Student 7,028 Points

C# Print word number of times depending on the input value

Can you help me.. How can I fix it?

Program.cs(10,14): error CS1519: Unexpected symbol for' in class, struct, or interface member declaration Program.cs(10,29): error CS1519: Unexpected symbol<' in class, struct, or interface member declaration Program.cs(10,37): error CS1519: Unexpected symbol ;' in class, struct, or interface member declaration Program.cs(10,41): error CS1519: Unexpected symbol++' in class, struct, or interface member declaration Program.cs(11,12): error CS9010: Primary constructor body is not allowed

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
        Console.Write("Enter the number of times to print \"Yay!\": ");
        int number = Int32.Parse(Console.ReadLine());
        }
           for(int i = 0; i < number; i++)
           {
             Console.WriteLine("word!");
           }
    }
}

1 Answer

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Tomasz,

You're receiving that error becuse you have the for loop outside of the Main function block. Also, make sure you change your WriteLine method to print "Yay!" instead of "word!" to pass the challenge.

I hope this helps. If you have any other questions please let me know.