-5
                for (j = 0;j < recipe.Count; j++) 

recipe is a list

                {

                    for (i = 0;  i < 9; i++) 
                    {

                        if (recipe[j] == tempFoodname)
                        {

                            for (int k = 2; j < 9; j++)
                            {

                                nutOneH[k] += double.Parse(nutrientArray[i, k]) * (nutrientListGram[j] / grams);

nutrient array is a huge array that carries a lot of data that is read from a text file

                            }

                        }

                    }
                }
                for (int k = 2; j < 9; j++)
                {

                    nutServe[k] = nutOneH[k] * (servings / 100);
                }
SumDum
  • 1
  • Read up about [step by step debugging](https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-debugger) – Martheen May 05 '20 at 23:22

1 Answers1

1

It is iterating over the lists of recipes:

 for (j = 0;j < recipe.Count; j++) 

looking for the right one:

if (recipe[j] == tempFoodname)

It also does something with the nutrientArray[i, k], which is a 2-dimensional array. And I have to say, I really hate those. They are just a pain to iterate over. I prefer jagged arrays every day of the week.

Just based on the names, I would say it is trying to figure out the "nutrients for one Helping" (nutOneH), which happens to be a array. But I can not figure out that formula at all:

nutOneH[k] += double.Parse(nutrientArray[i, k]) * (nutrientListGram[j] / grams);

And this one seems plain broken. It initialize k, uses k in the loops - but counts up j. The formula seems about figuring out "Nutrients from one Serving" from the one per helpings? Apparently 1 helping is 100 servings and you need the proper fraction based on actual servings requested?

for (int k = 2; j < 9; j++)
{
    nutServe[k] = nutOneH[k] * (servings / 100);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Christopher
  • 9,634
  • 2
  • 17
  • 31