Suppose the fly is at the wall. And suppose this will be the last trip or partial trip of the fly. Suppose the car is $h$ miles away.
The fly and and car have a combined speed of $140 \frac {km}{hr}$ so the fly reaches the car in $\frac h{140}$ hours. In that time the car has traveled $40\frac h{140} = \frac 27h$ and is now $h-\frac 27h = \frac 57h$ from the wall. So the fly heads back to the wall.
As the trip back is just as far this takes $\frac h{140}$ hours and the car has traveled another $\frac 27h$ and is now $\frac 37h$ from the wall. [1]
So the fly starts another trip, contradicting that this was his last. So the fly never makes a last trip an instead there are an infinite number of trips.
Figuring out how far the fly flies is a matter of noting the car is on a straight path and travels $20km$ at $40 kmh$ so this takes $30$ minutes. The fly no matter how many times (infinitely many) it zigs will travel at $100kmh$. So in $30$ minutes it flies $50 km$.
If one wishes to set this up as an infinite sum.....
Each trip the fly flies $\frac {10}7$ of the distance the car was away. And each trip the car is $\frac {3}{7}$ of the distance it was before. So the distance the fly travels is $\sum_{k=0}^{\infty} \frac {10}7*(\frac {3}{7})^k*20$ which if I did this correctly is
$\frac {10}7*20(\sum_{k=0}^{\infty} (\frac {3}{7})^k)= \frac {200}{7}\frac 1{1-\frac {3}{7}} = \frac {200}{7}\frac {7}{4}= 50$km.
[1](for the record, in this time, $\frac 1{70}h$ hours, the car has traveled $\frac 47h$ and the fly has travelled $\frac {10}7h$).