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

Niyazi Piriyev
Niyazi Piriyev
970 Points

C# basics last challenge, there is a bug,

1st question supposed to print n times (user input), but it prints 1 less then - smth wrong then I added 1 in order to pass to the next question. second question requires same code inside try / catch, this time it gives error because it prints 1 more time than supposed. then I fixed this one as well , in this case it says 1st question no longer passing.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            try{
                int i = 0;
                i = int.Parse(Console.ReadLine());

                for(int x = 0; x < i; x++)
                {
                    Console.Write("Enter the number of times to print \"Yay!\": ");

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

1 Answer

Steven Parker
Steven Parker
229,644 Points

You should only ask for the input one time, before the input or the loop.

Then, inside the loop, you only need to output "Yay!".