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

Todd Bascombe
seal-mask
.a{fill-rule:evenodd;}techdegree
Todd Bascombe
Full Stack JavaScript Techdegree Student 11,133 Points

i need help

i am kept getting errors , where did i go wrong

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            try
            {
                int amount = int.Parse(Console.ReadLine());
                Console.Write("Enter the number of times to print \"Yay!\": ");
                int counter = 1;
                while (amount >= counter)
                {
                    String type = amount.GetType().ToString();

                    if (type == "System.Double")
                    {
                        Console.Write("You must enter a whole number");
                    }
                    Console.WriteLine("Yay!");
                    counter++;
                }
            }
            catch (FormatException)
            {
                Console.Write("You must enter a whole number");
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

Here's a couple of hints:

  • write out the prompt before you read in the answer
  • since the try/catch will detect bad input when the "int.Parse" fails, you don't need to test the type directly