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 trialMojisola Sodunke
Courses Plus Student 2,034 PointsC# Basics: Code Challenge 1 of 3 Final. It says Bummer! I entered 5, but saw Yay! printed 6 times, instead of 5 times
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": "); var entry = Console.ReadLine();
var numberTime = int.Parse(entry);
int counter = 1;
while(counter <= numberTime)
{
if( numberTime <= 0)
{
break;
}
else if(numberTime > 0)
{
Console.WriteLine("Yay!");
counter += 1;
}
}
Console.WriteLine("You have printed \"Yay!\" " + entry + " times");
Console.WriteLine("The Program has loop: " + entry + " times");
}
}
}
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var entry = Console.ReadLine();
var numberTime = int.Parse(entry);
int counter = 1;
while(counter <= numberTime)
{
if(numberTime <= 0 && counter <= 0)
{
break;
}
else if(numberTime > 0)
{
Console.WriteLine("Yay!");
counter += 1;
}
}
Console.WriteLine("You have printed \"Yay!\" " + entry + " times");
Console.WriteLine("The Program has loop: " + entry + " times");
}
}
}
3 Answers
Steven Parker
231,269 PointsFor best results for all challenges, always do only what the instructions ask for. Anything extra, even if the code is otherwise good, can confuse the validator and cause it not to pass your submitted code.
Happy coding!
Steven Parker
231,269 PointsThe instructions didn't ask for any statistics to be printed out. It's probably counting the the word from that line also.
Mojisola Sodunke
Courses Plus Student 2,034 PointsAnd i have resolve it thanks to you