1) You must define your terms. Notation is not always the same. Various authors and teachers use various notations. What are 'r' and 're'? Have they names or relationships?
2) The problem statement is insufficient. We do not know the terms of the loan. What it the interest crediting methodology? What is the payment frequency? No lumps?
3) You have some rounding problems. If you are using the effective monthly interest to only two decimals, you should have some problems. 100000*0.039 = 3900. There are still two zeros to the LEFT of the decimal! How are you going to get exact pennies out of that? You need at least four more decimal places. Of course, this still won't help for the reasons in the next note.
4) Please see note #1. Notice how this has a zero you didn't have before digits are non-zero. Your version is off by an order of magnitude. 0.039 just won't do.
5) Do NOT memorize a formula for 1/2 the remaining balance. Just learn how to calculate values. Once you've the exact payment, you can calculate the value for ANY number of remaining payments.
If i = 0.04, then and . , so p = 413.51.
Just solve for 'n'