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 trialKeanu Barnard
2,018 PointsCould someone please help with the whole challenge ?
Im having huge trouble understanding what to do , could someone explain it to me please
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
}
}
}
1 Answer
jcorum
71,830 PointsHere you go:
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
int i = 0; //counter for while loop
int numTimes = 0; //variable to hold user input
String times = Console.ReadLine(); //get user input
try
{
numTimes = int.Parse(times); //see if it is an int
}
catch
{
Console.Write("You must enter a whole number."); // write error message if not
}
if (numTimes < 0) //see if user input is positive
{
Console.Write("You must enter a positive number."); // write error message if not
}
else
{
while (i < numTimes) //loop numTimes
{
Console.Write("\"Yay\"! ");
i += 1; //increment loop counter
}
}
}
}
}
Keanu Barnard
2,018 PointsKeanu Barnard
2,018 PointsThank you im trying to figure it out which to write first haha for section 1