Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Hianoo Song
Hianoo Song
6,812 Points

I can't find the reason why I'm getting "Bummer" sign on this

I tested this code on my workspace. and It did go well. I caught FormatException. and I got the number of "yay" I intended in ReadLine(). please help me (ㅠ_ㅠ)

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            int intNum = 0;
            bool gotNumber = false;
            while(!gotNumber){
              try{
                Console.Write("Enter the number of times to print \"Yay!\": ");
                string stgNum = Console.ReadLine();
                intNum = int.Parse(stgNum);
                gotNumber = true;
              }catch (FormatException){
                Console.Write("You must enter a whole number.\n");
              }catch (ArgumentNullException){
                Console.Write("You must enter a whole number.\n");
              }
            }
            int i=0;
            while(i < intNum)
            {
              Console.Write("\"Yay\"");
              i += 1;
            }

        }
    }
}

2 Answers

Tarek El Hinaoui
Tarek El Hinaoui
Courses Plus Student 13,220 Points

you can get rid of catch (ArgumentNullException){ Console.Write("You must enter a whole number.\n"); }

Hianoo Song
Hianoo Song
6,812 Points

I also tried getting rid of argumentnullexception catch but Answer Checking Button wouldn't go next..

Tarek El Hinaoui
PLUS
Tarek El Hinaoui
Courses Plus Student 13,220 Points

Just managed to repass the code challenge [SOLVED]

catch (Exception ex) when (ex is FormatException || ex is ArgumentNullException ){ Console.Write("You must enter a whole number.\n"); }