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 trialJordan Lassiter
Courses Plus Student 347 PointsCode is not validating the <=0 if statemenet
When I run my code with the
if(minutes <= 0)
{
Console.WriteLine(minutes + " is not an acceptable value.");
continue;
}
the program still seems to jump to the else if statement "Better then nothing"
here is the full code thank you in advance for the help
using System;
namespace Fitness.AP
{
class Program
{
static void Main()
{
int runningTotal = 0;
bool keepGoing = true;
while(keepGoing) {
// Prompt user for minutes exercised
Console.Write("Enter how many minutes you exercised or type \"quit\" to exit:" +" ");
// gathering input from user
string workoutmin = System.Console.ReadLine();
if(workoutmin == "quit")
{
keepGoing = false;
}
else
{
int minutes = int.Parse(workoutmin);
if(minutes <= 0)
{
Console.WriteLine(minutes + " is not an acceptable value.");
continue;
}
else if(minutes <= 10)
{
Console.WriteLine("Better than nothing, am I right?");
}
else if(minutes <= 30)
{
Console.WriteLine("Way to go hot stuff!");
}
else if(minutes <= 60)
{
Console.WriteLine("You must be a ninja warrior in training!");
}
else
{
Console.WriteLine("Okay, now you're just showing off!");
}
runningTotal= runningTotal + minutes;
//writing user input back to them
Console.Write("You have entered:" + " " + runningTotal + " " + "Minutes" + "\r\n " );
}
}
Console.WriteLine("Bye");
}
}
}
Robert Anthony
19,952 PointsWhat exactly did you type in as the input?
2 Answers
Steven Parker
231,269 PointsThis program seems to build and run without errors.
You will see the "Better than nothing, am I right?" message when you enter a number between 1 and 10 (inclusive).
Erik Gabor
6,427 PointsI think the problem is that you run and older .exe and you did not compile the current modifications. I've tested the program for negative and 0 values and it does not go to "Better than nothing"
Steven Parker
231,269 PointsSteven Parker
231,269 PointsTo allow a full analysis of the issue, make a snapshot of your workspace and post the link to it here.