✅ I don't know why this doesn't work.
I am doing the first task of advent of code in C# and I have problem with my code. I am not sure how to solve it and I been at it for about over an hour. my code doesn't set a variable value to 0 when I want it and I don't understand why.
the input file is from first task on advent of code.
13 Replies
Did you put a breakpoint and saw that
currentCalories
wasn't set?yep. it wasn't being set to 0. the value of currentCalories just keeps being added up.
So "space" isn't getting printed to the console as well?
it is being printed.
I'm talking about this line
Console.WriteLine("space");
yeah. space is being printed when string input parsing fails.
Which means
currentCalories
is getting set to 0 it is getting there but the value of highestCalories is 166752036 which is way too big
I figured it out.
currentCalories += currentCalories + number;
my logic is bad.
currentCalories = currentCalories + number;
Which could be shortened to just
currentCalories += number
thank you for the help. what do I do with this post? delete it or move it to "closed" or something?
just
/close
Closed!