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

I can't figure out why this won't compile online..it compiles in Visual Studio 2015 perfectly!

This will not compile in my workspace, but will compile in VS 2015 community perfectly. Im thinking its a string formatting issue, but could use some help with it. The solutions I found in the community seem to be over kill because they check for validation errors -- which wasn't in the challenge spec. Can somebody help, Please?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("The prompt should print: Enter the number of times to print \"Yay!\"");
            var input = Console.ReadLine();
            var counter = Convert.ToInt32(input);
            var count = 0;

            while (count < counter)
            {
                Console.WriteLine("\"Yay!\"");
                count++;

            }

        }
    }

}

2 Answers

You are right, it is a formatting issue. Nothing is wrong with your code semantically and it works as intended. It just isn't passing the checks on Treehouses automated testing.

If I were you, I would save everything after the console.write() line and restart to a fresh template by clicking the restart button on the challenge.

The string the challenge provides for you is already valid. Just add everything back in after that call to Console.write() and you will pass.

hm..that didn't get it. Here's the code with the write() method changes.

var input = Console.ReadLine(); var counter = Convert.ToInt32(input); var count = 0;

while (count < counter) { Console.WriteLine(count + "yah!"); count++;

}

You can't put count in the string that console.WriteLine outputs in the loop. It just wants you to output yay! (not yah like you have) and nothing else.

Again, it seems you're getting caught by the formatting, but this time on the yah! instead of the first one. make sure the output is:

                Console.WriteLine("yay!"); 

if you include anything else in there, including the count variable, you will not pass the test as the checks are looking for strings that literally just are "yay!"