How do I do this program?

See post#23 and don't thank me thank @anon73444976, he gave the hint see post#19, I only expanded the hint but does it meet your criteria?