The reason why is because year
is only a single element. When you move to the next iteration, you are traversing out of bounds as year
is just a single element but you are trying to access the non-existent second element.
The reason why year
is a single element is due to the year = data_register(i)
assignment. You need to change the age
assignment to the following:
age = 2014 - year;
Aside
Your for
loop doesn't make any sense to me. I'm not sure why you are using age
when you aren't using it in the statements that follow it. What is A22
? B22
? Is it related to age
? How are these being calculated?