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 trialLiam Andersson
1,396 PointsIs this a bug? Or am I missing something?
(It worked with double once then it didnt work lol)
I removed "int" and replaced it with "doubles" instead so I could type decimals in the application! But I have a problem. I dont know why, but one function stopped working. My "You have entered" + minutes + "." stopped working and I cant figure out why. I dont get any error but the code just wont work the way I want it to.
Code: https://w.trhou.se/mtr2a64468
It doesnt work switching out doubles with int. What's the problem really?
Steven Parker
231,210 PointsWhen pasting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
But even better, you can make a snapshot of your workspace and post the link to it here. That will also make it much easier to test the solution.
Liam Andersson
1,396 PointsAh like this? So I can send you this link and you will be linked to my snapshot?
1 Answer
Steven Parker
231,210 PointsUsing the snapshot, I tried the program and noticed that it only prints out the total if the number you enter is greater than 60. I found it difficult to see the program flow looking at the source because of how it is indented. But here's the "try" section re-indented to show nesting levels:
double minutes = double.Parse(entry);
if (minutes <=10)
{
System.Console.WriteLine("Better than nothing right?");
}
else if (minutes <= 30)
{
System.Console.WriteLine("Great job! Give yourself a pat on the back!");
}
else if (minutes <= 60)
{
System.Console.WriteLine("Are you a ninja warrior or what?!");
}
else
{
System.Console.WriteLine("I think I've found the new superman!");
if (minutes <=0)
{
System.Console.WriteLine(minutes + " isn't an acceptable value, please try again!");
continue;
}
//Add minutes exercised total
runningTotal = runningTotal + minutes;
// Display total minutes exercised to the screen
System.Console.WriteLine("You have entered: " + runningTotal + " minutes");
// Repeat until user quits
}
This makes it easier to see that the code in the final "else" only runs when the input is more than 60, and the test for "minutes <= 0
" will never be true .
I expect that you will want to make some changes to the program flow so that the total can be accumulated (and output) for values below 60. Perhaps the whole issue is caused by a closing brace in the wrong place.
Liam Andersson
1,396 PointsSadly I don't get it.. I even double checked the instructors notes. How come that only when it is over 60 the " You have entered" code will run?
Steven Parker
231,210 PointsYou have an "if...else if" chain that checks for different input values and the final "else" only runs when the value is more than 60. The code that outputs that message is inside that "else" block (but probably should not be).
Try moving the close brace that is currently on line 56 up between lines 41 and 42.
Liam Andersson
1,396 PointsNevermind I fixed the error. I took a closer look at the "else" and saw that I missed some brackets there and here. I dont know how it happened though! Thanks for your help anyway!
Liam Andersson
1,396 PointsLiam Andersson
1,396 PointsI dont know why it wont show the whole code, but I hope you can figure it out anyway! Thanks for any answer!