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

Am I doing it right?

I'm on the final task of the C# Basics course (woohoo!) and I would like to be told whether or not I am on the right track to finishing this.

EDIT I'll finish this later on maybe

Program.cs
using System;

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

           try
           {
                    // code goes here
               Console.Write("Enter the number of times to print \"Yay!\": ");
            string input = Console.ReadLine();

            int count = int.Parse(input);

            if(input <= 0)
            {
                Console.Write(input + " You must enter a positive number.");
                continue;
            }
            else if(input >= 1)
            {
                Console.Write(input
            }
            int i = 0;
            while(i < count)
            {
                i += 1;   
                Console.WriteLine("Yay!");
            }
           }
           catch (FormatException) // The catch block should catch FormatException exceptions
           {
                    //Inside of the catch block, output to the console the message "You must enter a whole number."
               Console.Write("You must enter a whole number.");
           }
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,210 Points

Four things stand out for me at first glance:

Though you have converted the input into a number ("count"), there are a couple of lines where the original string ("input") is being compared with a number.

And this statement appears to be incomplete:

                Console.Write(input

It's also not clear why anything would be output at that point in the program.

Third, there's a "continue" statement but it's not inside a loop (they are only allowed in loops).

And finally, one of the output messages is different from what the instructions asked for.

ok, thanks

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Didn't you complete this yesterday? https://teamtreehouse.com/community/needing-help-again

Anyway, the challenge don't tell you to add an if/else if statement - remove it.

Other than that it looks fine - try remember to indent your code to make it more readable :-)

I only completed the first task then went to bed and thanks :P