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 trialChristian Broomhall
790 PointsHow do you subtract 1 from the total number of "Yay!!"s before the program loops again?
I've created a loop for the program to display "Yay!". But I can't figure out how to let the program know to subtract 1 from the entry before it loops itself.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
bool keepGoing = true;
while(keepGoing)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string entry = Console.ReadLine();
double number = double.Parse(entry);
if(number <1)
{
keepGoing == false;
}
else
{
Console.WriteLine("Yay!");
number -= 1;
}
}
}
}
}
1 Answer
Steven Parker
231,236 PointsYour subtraction is good.
But it is a problem if the loop includes the code that prompts the user and then takes in the input and converts it. All of that should happen only one time, before the loop starts.
Also, when you set keepGoing to false, you need to use an assignment operator ("=
") instead of a comparison operator ("==
").