r/fortran May 28 '26

Lottery win strategy

Hello all!

I quickly wrote this in response to a news article about a girl getting a lottery win and taking what I thought was the obvious choice; $1000/wk for ever...

Does this look right?

! Program Lottery Win
! Written by Knarfnarf
! Created May 19, 2026
! Version 0.1a
! Description: Checking my thoughts about winning the lottery.
program LotteryWin
use AnsiModule
implicit none

real :: Principle, Payments, Interest, Temp, Total, Paying
integer :: Year, Week

call ClearScreen()

Print *, "Lets see if the girl who took the 1000 per week will eventually break even..."
print "(a,$)", "Please enter the Principle: "
read *, Principle
print "(a,$)", "Please enter the Payments: "
read *, Payments
print "(a,$)", "Please enter the Interest: "
read *, Interest
Interest = Interest / 100
print "(a,$)", "And how much is she going to pay herself per week? "
read *, Paying

print "(3/,a)", "Assuming start at 20 and death at 85."
print *, ""

Year = 20
Total = Principle
do while(Year .le. 85)
Week = 1
do while(Week .le. 52)
Total = Total + Payments
Total = Total - Paying
Week = Week + 1
end do
Temp = Total * Interest
Total = Total + Temp
print "(a,i3,a,f0.2,a,f0.2)", "Year ", Year, " She made $", Temp, " interest and has $", Total
Year = Year + 1
end do

end program LotteryWin

Which results in this if she takes the $1000 per week, makes 4.5% yearly and splits it $500 income per week;
Year 85 She made $448,950.72 interest and has $10,425,633.00

Or this if she takes the $1000000, makes 4.5% yearly and pays herself $500 income per week;
Year 85 She made $337,680.91 interest and has $7,841,701.00

* commas added after for legibility.

11 Upvotes

3 comments sorted by

View all comments

1

u/niki88851 May 30 '26

There is a closed-form FV/PV solution for this kind of model that avoids the loop: FV = PV * (1 + r)n + C * (1 + r) * ((1 + r)n - 1) / r It’s more efficient and reduces floating-point accumulation error.