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 trialMargaret Macharia
8,870 PointsWhat i am i doing wrong?
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": "); System.Console.Write("Enter number of times to enter Yay!"); var numOfTimes = System.Console.ReadLIne(); int num = int.Parse(numOfTimes); for (int i=0; i<input; i++) { Console.WriteLine("\"Yay!\""); }
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
System.Console.Write("Enter number of times to enter Yay!");
var numOfTimes = System.Console.ReadLIne();
int num = int.Parse(numOfTimes);
for (int i=0; i<input; i++) {
Console.WriteLine("\"Yay!\"");
}
}
}
}
3 Answers
Edward Ries
7,388 PointsYou have 2 problems not counting the extra console.Writeline.
The first is Console.ReadLIne() should be Console.ReadLine() <- Capital I is causing a compile error The 2nd issue is your for loop has while I < input but you just used int.parse to put the number into "num"
var numOfTimes = Console.ReadLine(); // <- change ReadLIne to ReadLine
int num = int.Parse(numOfTimes);
for (int i=0; i<num; i++) { // <- change input to num
Console.WriteLine("\"Yay!\"");
}
These kinds of errors happen all the time. Even with seasoned developers but we learn techniques to deal with them. For example, I scanned each line of code and looked at each command to make sure I understood what it was doing, where any variables are initialized and to check to see if they are in scope, and then to make sure everything is spelled correctly.
Keep up the good work.
Steven Parker
231,236 PointsIt looks like you have 3 separate issues:
- You spelled "ReadLIne" with a capital "I" (it should be "ReadLine")
- Your loop compares the index to "input", but the variable storing the count is "num"
- You added a line that prints "Enter number of times to enter Yay!", but the challenge had already provided one.
Edward spotted the first two of these, but you must also fix the third one or the challenge will misinterpret it as producing the wrong count of outputs.
Margaret Macharia
8,870 PointsAm still getting an error.