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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Kari Soto](https://secure.gravatar.com/avatar/cfae5aa6e71a86041f2bd9371e38d68c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Kari Soto
1,836 PointsI completed the "Final" on workspaces, but it doesn't work on the final. Does anyone have a working version?
Here is my code:
// Type "clear && macs Program.cs && mono Program.exe" in the console without quotes to start the program.
// Type "quit" to quit.
using System;
namespace Treehouse
{
class Program
{
static void Main()
{
while (true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
try
{
string input = Console.ReadLine();
if (input == "quit")
{
break;
}
int newNumber = Int32.Parse(input);
while(newNumber != 0)
{
Console.WriteLine("\"Yay!\"");
newNumber -= 1;
}
}
catch (FormatException)
{
Console.WriteLine("That is not a valid input.");
}
}
}
}
}
Thanks!
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 Points
Your program "works", but deviates from the instructions.
This is a great example of how something that works (will compile an run) might not be what was asked for (satisfies the requirements). This has been a topic of many previous questions, but I'll repost the info here:
People often over-think this one and get too creative, and their answer is rejected for a variety of reasons (some which don't seem to make any sense).
Here are the secret "rules" you must follow for success on this one:
- Your program must ask for and accept input ONE TIME ONLY
- If the input validates, your program will perform exactly as in Task 1
- If the input does not validate, it will print the error message and exit
- Validation must be done by exception catching. There are other perfectly good methods that can be used for validation, but they will not pass this challenge
![Sean Hayes](https://secure.gravatar.com/avatar/43282e747dacb30d6a3a479777c6b318?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sean Hayes
Courses Plus Student 8,106 PointsI agree with Steven, I think you are over thinking the program and trying to do more than what is asked. Take a look at what is asked and what you wrote:
- Get input from the user on how many times they want to print "Yay!".
- You will have to try (hint) to convert this input to an int (hint) to make is useful in a for (another hint) loop.
- You need to check if that input is positive (greater than or equal to 0) (hint)
- Run a for-loop printing Yay! to the screen (watch how many times you use double quotes).
- And if the try fails because the user put in a word instead of a number, catch the exception.
That is all you have to do for this challenge. There is no need for a while loop, and check which flavor of int you are using for the parse. Hope this helps.
![Kari Soto](https://secure.gravatar.com/avatar/cfae5aa6e71a86041f2bd9371e38d68c?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Kari Soto
1,836 PointsThanks!
Kari Soto
1,836 PointsKari Soto
1,836 PointsThanks!