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 trialJude Brown
Courses Plus Student 629 PointsBummer! I entered 5, but saw Yay! printed 1 time. Did you modify the while loop?
Hello,
I have commented throughout the code. My while doesn't appear to be repeating. Have a I declared variables incorrectly? I'm grasping at straws here. Just rewatched the try catch, heading back to the while videos.
Thanks in advance,
Jude
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
try
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string input = Console.ReadLine();
//Ask user to input how many times they want to see yay. Convert that input into a string.
int count = int.Parse(input);
//New variable called count that is the user input converted into an integer.
int i = 0;
while(i < count)
i += 1;
Console.WriteLine("Yay!");
//Setting variables for the while to work. Int is set to 0. Somehow as the while runs the code
//is able to remember the last state of i and ad 1 to it. Increasing until the while is not true.
}
catch(Exception)
{
Console.Write("You must enter a whole number.");
//If the user inputs something other than a whole number we will catch it here and send them
// back to the start of the try. My assumption is that is built into the Try/Catch method.
}
}
}
}
2 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsYou're missing { } for your while-loop
while(i < count)
// missing {
i += 1;
Console.WriteLine("Yay!");
// missing }
Jude Brown
Courses Plus Student 629 PointsThank you Henrik!