Seems to work fine for me - how are you running the app?
working on this module https://learn.microsoft.com/en-us/training/modules/csharp-arrays/
Using this code my outcome is below:
int[] inventory = { 200, 450, 700, 175, 250 };
int sum = 0;
int bin = 0;
foreach (int items in inventory)
{
sum += items;
bin++;
Console.WriteLine($"Bin {bin} = {items} items (Running total: {sum})");
}
Console.WriteLine($"We have {sum} items in inventory.");
OUTCOME I get is this: Bin 5 = 250 items (Running total: 1775) We have 1775 items in inventory
The module says it should be this:
Bin 1 = 200 items (Running total: 200) Bin 2 = 450 items (Running total: 650) Bin 3 = 700 items (Running total: 1350) Bin 4 = 175 items (Running total: 1525) Bin 5 = 250 items (Running total: 1775) We have 1775 items in inventory.
I was wondering why I was not able to get the correct answer. I have even copied and pasted the code from the module, but I am still getting the wrong answer.
1 additional answer
Sort by: Most helpful
-
Billee Mason 20 Reputation points
2024-08-17T07:34:16.6633333+00:00 Thanks very much for replying to me.
It seems to work perfectly today - who knows, yesterday, maybe gremlins were about.