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

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"); }