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

Code is working on visual studio 2015 but it's crashing on this webside

it says i entered 5 times but its give me -1

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            int b = 0;
            //Returned here
        enbas:
            string a = Console.ReadLine();
            //Ask gain
            if (a == "Yay!")
            {
                //add if its YAY!
                b++;
                Console.WriteLine("Enter the number of times to print \"Yay!\": " + b);
                goto enbas;
            }
            //if it's not finish it 
            Console.ReadKey();
        }
    }
}

1 Answer

Steven Parker
Steven Parker
229,644 Points

:point_right: This program works, but it does something very different than required.

The "Bummer" response about "-1 times" is a bit misleading (and impossible!), but some of what you wrote is very different from what the challenge asks for:

  • the program will print "Yay!", the user does not enter it.
  • the user will enter the number of times to print.
  • when the printing is done, the program will end
  • the number will be the only thing entered (you won't need ReadKey)

Try again, and be sure to follow the instructions carefully.

Also, while it won't affect the challenge, it's generally considered bad practice to use goto to create loops. Try using one of the loop methods introduced in the course.

Thanks for helping.