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

Pulla Rao Charugalla
PLUS
Pulla Rao Charugalla
Courses Plus Student 2,755 Points

I am in the final section of the c# basic course. stuck on task1 of 3 about printing yay! excersize

what would be wrong with the following code? after i compile it using codechallenge it says bummer,try agin! please fix it. i could not proceed.

using System;

namespace Treehouse.CodeChallenges { class Program { static void Main() { int Yaycount = 0; while (true) { Console.WriteLine("Enter the number of times to print \"Yay!\":"); string snooftimes = Console.ReadLine();

if (snooftimes == null) { Console.WriteLine("Invalid input"); continue; }

if (snooftimes.ToLower() == "quit") break; try { int inooftimes = int.Parse(snooftimes); for (int i = 0; i < inooftimes; i++) { Console.WriteLine("Yay!"); Yaycount++; } } catch (Exception) { Console.WriteLine("Invalid input"); continue; } } } } }

Program.cs
using System;

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

        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,236 Points

It looks like you have a loop that keeps the program from ending.

It's hard to read without proper formatting (Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:), but it looks like you added a loop around the part that asks the user for a count and gets the answer.

The prompt and input should only happen one time, and if the answer is good, it should output some "Yay!"s. If the answer is not good, it should print an error message. Either way the program should end.

Also, be sure to output the exact error messages given in the instructions.