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

Roman Devera
Roman Devera
1,227 Points

Hello, I just wrote a code for the final challenge in C# basic module. However, the testing mechanism did not let me pas

Hello, I just wrote a code for the final challenge in C# basic module. However, the testing mechanism did not let me through despite the program is doing what is supposed to. Please, help me to pass the challenge. Thanks

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {



           int pocetZobrazeni = 0;


            while (true)
            {
                try
                {

                    Console.WriteLine("Enter the number of times to print \"Yay!\": ");
                    pocetZobrazeni++;

                    int kolikrat = int.Parse(Console.ReadLine());
                    int pridat = 0;


                    while (true)
                    {
                        if (pridat == kolikrat)
                        {



                            break;

                        }
                        else
                        {
                            Console.WriteLine("YaY");
                            pridat++;
                        }

                    }

                }
                catch
                {
                    Console.WriteLine("Mistake");
                }


                 Console.WriteLine("Celkovy pocet zadani " + pocetZobrazeni); 

            }






        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,210 Points

You have too many loops. A program built according to the instructions will prompt and accept input one time, and based on the input it will either print "Yay!"s or an error mesage. Either way, it should end. With the extra loop it never ends.

Also, the challenges are picky about output messages. Be sure you output the exact (English) messages asked for by the instructions.

Roman Devera
Roman Devera
1,227 Points

Hi Steven, thanks for your answer. It actually helped me to get through the challenge. Thank you!