#### jj2007

• Member
• Posts: 13311
• Assembly is fun ;-)
##### Calculate your daily water consumption
« on: May 30, 2022, 06:39:04 AM »
Init
MovVal ST(0), Input\$("\nConsumption: ", "500")               ; ask e.g. for cubic metres of water
movaps xmm1, TimeSF(Input\$("older date: ", fDate\$(-30)))     ; suggest thirty days before today
psubq TimeSF(Input\$("newer date: ", fDate\$())), xmm1         ; subtract from today
FpuPush TimeDiff(d)
Print Str\$("%i days between the two dates\n", ST(0))         ; display difference in days
fdiv
Inkey Str\$("Consumption per day: %3f units", ST(0)v)         ; calculate consumption per day
EndOfCode

The strings "500", fDate\$(-30) and fDate\$() are suggestions and can be edited by the user with the arrow and backspace keys. The consumption can be any number, e.g. 1.5; the dates must be entered in the correct format dd.mm.yyyy - sorry, U.S. format won't work

Example:

Code: [Select]
`Consumption: 500older date: 29.01.2022newer date: 29.05.2022120 days between the two datesConsumption per day: 4.17 units`
Macros used: MovVal, Input\$(), TimeSF(), fDate\$(), TimeDiff(), FpuPush, Str\$(), Inkey