I'm having trouble getting the correct addition in my array.
1 2 3 4 5 6 7
for (int k = 0; k < ARRAY_SIZE; k++)
{
if (contents[k].locker_num != 0)
{
avg_sum += contents[k].texts;
}
}
Whenever I run the code, if I use (as an example) contents[0].texts = 10 and contents[100].texts = 20 It gives me avg_sum = 40
I've been effing with it for an hour and cant get it to produce the right answer( would be 30 in this case)
if you cant see, im trying to add every spot in the array that doesn't have a locker_num of 0.
constshort ARRAY_SIZE = 101;
short avg_sum = 0;
Locker contents[ARRAY_SIZE];
//this loop initializes all locker_num to 0
//...which is how the program controls which lockers are in use
for (int i = 0; i < ARRAY_SIZE; i++)
{
contents[i].locker_num = 0;
}
//initializes all lockers to have no texts.
for (int j = 0; j <ARRAY_SIZE; j++)
{
contents[j].texts = 0;
}