Here's what I see about your original code:
If you used this declaration for your array of readings -
const int maxReadings = 20;
then the compiler has set aside 20 integer-sized memory locations for the array. If you later execute this -
numReadings = 100;
- then your program will read from, and write to, 100 locations, 80 of which aren't reserved for the array, and many of which may be in use for storing something else. We don't know what variables use those locations, but they might be index, total, or average, in which case you'd be writing analog readings to those variables. I'm not surprised that you got unexpected results.
If you want the maximum number of readings to be as high as 100, under program control, then you'll need to declare your array of readings to have space for 100 values. Otherwise, chaos ensues.