That is because this code does not read each n from the file, it just reads once from the file and sets it to maxDen thats it. You would require to read n and set it to maxDen every time so that it would require another for / while / do-while loop. Thats what the assignment statement reads
Requires nested loop with the inner loop summing up series and outer loop allow inner code to repeat once for each n read in from file