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

Could someone please help with the whole challenge ?

Im having huge trouble understanding what to do , could someone explain it to me please

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
        }
    }
}

1 Answer

Here you go:

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");

            int i = 0;   //counter for while loop
            int numTimes = 0;  //variable to hold user input

            String times = Console.ReadLine();  //get user input

            try
            {
                numTimes = int.Parse(times);  //see if it is an int
            }
            catch
            {
                Console.Write("You must enter a whole number.");  // write error message if not
            }
            if (numTimes < 0) //see if user input is positive
            {
                Console.Write("You must enter a positive number.");  // write error message if not
            }
            else 
            {
                while (i < numTimes)  //loop numTimes
                {
                    Console.Write("\"Yay\"! ");  
                    i += 1;  //increment loop counter
                }  
            }
        }
    }
}

Thank you im trying to figure it out which to write first haha for section 1