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 trialPaul Willis
4,082 PointsProblem passing C# code challenge
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var repeat = int.parse(Console.ReadLine());
var count = 0;
var brake = false;
While (brake == false){
Console.WriteLine("Yay!");
Count += 1;
If (count == repeat){
brake = true;
}
}
}
}
}
3 Answers
Paul Ryan
4,584 PointsFrom first glance, your count variable in the loop is uppercase. It should be lowercase.
Be careful with methods and ensure you are using the correct case. This will cause errors. Methods and variables are case sensitive.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
int repeat = int.Parse(Console.ReadLine());
while(repeat > 0){
Console.WriteLine("Yay!");
repeat--;
}
}
}
}
that is how I would approach it. Any questions just ask me.
Also noticed you are using var. I wouldn't recommend using var unless you have a very good reason.
Andrii Kodola
Full Stack JavaScript Techdegree Student 16,870 PointsAlso in int.Parse method "Parse" have to start from uppercase letter.
Christian A. Castro
30,501 PointsThanks Paul Ryan, very helpful!!
Brecht Philips
8,863 PointsBrecht Philips
8,863 PointsOr you can use this while(count <= repeat){ Console.Writeline("Yay!"); count++; } Or a for loop for(int i=0; i < repeat ; i++){ Console.Writeline("Yay!"); }