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

Emily Krebs
seal-mask
.a{fill-rule:evenodd;}techdegree
Emily Krebs
Front End Web Development Techdegree Student 6,438 Points

Is there something wrong with C# Basic Final project?

This is compiling and working just fine inside of workspaces. I cannot get anymore information on what it wants besides "Bummer! Try again!"

Also we never covered in this course how to submit multiple Exceptions for try catch

using System;

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

    {


      while (true)
      {
        //Prompt the user to enter the number of times they want "yay!" to print
          Console.Write("Enter the number of times to print \"Yay!\": ");
          string enteredInput = Console.ReadLine();
        //print yay that number of times

        try{
            int repeatYay = int.Parse(enteredInput);
            if(repeatYay <= 0)
            {
              Console.WriteLine(enteredInput + " is in incorrect format. Please, enter only whole positive numbers.");
            continue;
            }
            //exit program without crashing
            else 
            {
              int stoppingLoop = 0;
               while (repeatYay > stoppingLoop)
              {
              Console.WriteLine("Yay!");
                 stoppingLoop = stoppingLoop + 1;
              } 


                break;


             }
        }
        catch(FormatException)
        {


          Console.WriteLine("You must enter a whole number.");
            continue;

        }
        catch(ArgumentNullException)
        {


          Console.WriteLine(enteredInput + " is in incorrect format. Please, enter only whole positive numbers.");
            continue;

        }
      }
      Console.WriteLine("Goodbye.");
    }
}

}

If I don't have the catch(ArgumentNullException), then I can't pass the first round. However, this code only shows the "Bummer! Try again!" with nothing in the preview screen to add guidance to a solution. In addition if I take the ArgumentNullException, it tells me that I am no longer passing number 1 task.

Thanks for any help that can be offered.

Emma

1 Answer

Hi Emily,

Can you post your code so that we can take a look.

There are a number of different approaching to answering this type of task, but you are not going to need multiple exceptions for try catch. If you are thinking about task 3 ("Add more input validation to your program by printing “You must enter a positive number.” if the user enters a negative number."), the user entering a negative number is not going to trigger an exception. So you can just make use of an if statement and then depending on how you set up your loop you may need a break ... or maybe not depending on how you have structured your code.

When you are getting the "Bummer! Try again!" message, is there any extra information provided if you click on the 'preview' button?