The first time you enter the loop, you set totalPrice
to 0. Then you add the first item price, so totalPrice is 25. Then you enter the loop for the second time, set totalPrice
to 0 again, 0 + 50 = 50.
You should initialize totalPrice
before the loop.