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

can get my code to work as my continue statement is not restarting the loop

I am lost on why I get an error code for my code not working. I can see its to do with my continue statement but its almost identical to similar code I have written and cannot make out what I am missing for it to run correctly.

Program.cs
using System;

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

             try
                {
                Console.Write("Enter the number of times to print \"Yay!\": ");
                    int counter = 0;
                    String times = Console.ReadLine();
                    int totals = int.Parse(times);                    
                    if (totals < 0)
                        {
                        Console.Write("You must enter a positive number");
                        continue;
                        }
                    else 
                    {
                     while (counter < totals)
                         {
                         Console.Write("\"Yay\"! ");
                         counter = counter + 1;
                         } 
                    }

                  }


            catch (FormatException)
                    {
                    Console.WriteLine("You must enter a whole number");
                    }

        }
    }
}

1 Answer

Dov Brodkin
Dov Brodkin
2,695 Points

When you declared the variable times you capitalized String, you should write it all lower case instead 'string times = ...' (instead of 'String times = ...').