string[] lines = File.ReadAllLines("C:\\Users\\huber\\Desktop\\AdventOfCode2022\\task1\\task1\\input.txt");
int highestCalories = 0;
int currentCalories =0;
foreach (string line in lines)
{
string linetext ="";
int number = 0;
linetext = line.ToString().Trim();
bool success = int.TryParse(linetext, out number);
if (success)
{
currentCalories += currentCalories + number;
Console.WriteLine(number);
}
else
{
Console.WriteLine("space");
currentCalories = 0;
// I think this is the error. current calories do not get set to 0.
}
if (currentCalories > highestCalories)
{
highestCalories = currentCalories;
}
}
Console.WriteLine("Highest Calories {0}", highestCalories);
Console.ReadLine();
string[] lines = File.ReadAllLines("C:\\Users\\huber\\Desktop\\AdventOfCode2022\\task1\\task1\\input.txt");
int highestCalories = 0;
int currentCalories =0;
foreach (string line in lines)
{
string linetext ="";
int number = 0;
linetext = line.ToString().Trim();
bool success = int.TryParse(linetext, out number);
if (success)
{
currentCalories += currentCalories + number;
Console.WriteLine(number);
}
else
{
Console.WriteLine("space");
currentCalories = 0;
// I think this is the error. current calories do not get set to 0.
}
if (currentCalories > highestCalories)
{
highestCalories = currentCalories;
}
}
Console.WriteLine("Highest Calories {0}", highestCalories);
Console.ReadLine();