My code works fine up to three capacitive sensors touched. However, when I touch four capacitive sensors, it does not work!!
One thousand, two thousand, three thousand, forty thousand...
Not quite a linear progression.
Literals are treated as ints, unless indicated otherwise. You have not indicated otherwise, so 40000 is treated as an int. Look at the reference pages to determine the size of, and maximum value that can be stored in, an int. Hint: It's less than 40,000.