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

Ryan McMaster
Ryan McMaster
3,842 Points

Task 2, in the 3 part C# challenge is working, but returns an error saying task one no longer parses.

I am missing what I did wrong. I have tried a few different things but to no avail.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");

            var total = int.Parse(Console.ReadLine());

            int counter = 0;

            try
            {
                total = Convert.ToInt32(Console.ReadLine());
            } 

            catch (FormatException fe)
            {
                Console.Write("Invalid entry, You must enter a whole number.");
            }

        while (counter < total)
            {
                Console.WriteLine("Yay!");
                counter ++;
            }

        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,269 Points

The "task 1" part might be misleading.

Previous tasks are retested first, so if you have introduced a syntax error, it will always complain about task 1. But here's some hints about the actual issues:

  • you should only call ReadLine once, but your code does it two times
  • you can declare total without assigning it initially
  • the challenge is very picky about messages, you should output the exact string from the instructions
Ryan McMaster
Ryan McMaster
3,842 Points

Thank you Steven, I got it solved out!