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

I Don't know how to fix the error

the preview shows

System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex at System.String.Substring (Int32 startIndex, Int32 length) [0x0009c] in /builddir/build/BUILD/mono-4.4.2/external/referencesource/mscorlib/system/string.cs:1266 at System.String.Substring (Int32 startIndex) [0x00000] in /builddir/build/BUILD/mono-4.4.2/external/referencesource/mscorlib/system/string.cs:1232 at MonoTester.Run () [0x001b6] in MonoTester.cs:132 at MonoTester.Main (System.String[] args) [0x00013] in MonoTester.cs:28

what dose that mean

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
           int a =0;
            try
            {

               a =  Convert.ToInt32(Console.ReadLine());
                 for (int i=1; i<=a+1; i++) 
                {
                    Console.Write("Enter the number of times to print \"Yay!\": " + i);
                }

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




        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,108 Points

:point_right: You should go back to task 1.

I tried this in the challenge, and it passed task 1 — but it should not have, and the problems will become more serious in the latter tasks. Particular issues that need addressing for task 1:

  • You don't actually print "Yay!"
  • You don't print the prompt until after you take the input.
  • You print the prompt in a loop (instead of "Yay!").
  • The loop index should not be printed.

Start over at task 1 and be sure to fix these issues, then task 2 should go more smoothly.