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'm not sure why this is printing 53 times.

This doesn't make sense to me. This should be pretty straight forward.

I've tested this in workspaces too and I get a whole bunch of Yay!'s printed.

Program.cs
using System;

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

            Console.Write("Enter the number of times to print \"Yay!\": ");

            input = Console.Read();

            for (var n = 0; n < input; n += 1)
            {
                Console.Write("Yay!");            
            }

        }
    }
}

2 Answers

Eh... I solved it. Thanks.

Steven Parker
Steven Parker
231,248 Points

The input given must have started with the digit "5".

Since Console.Read returns the character value of the first character in the input stream, and the digit "5" has a character value of 53.

What you probably want instead is to use a different input method to get the entire input as a string, and then convert that string into a numeric value. Then use that as the count.