Mid-cycle plan change
A SaaS company in Berlin bills customers once per cycle. When a customer changes plan in the middle of a cycle, the unused part of the old plan is credited and the same remaining part of the new plan is charged. Cycles have different lengths (28 to 31 days), so the fraction is based on real days.
Let days be the number of days from the cycle start to the cycle end (end date excluded, it is the next renewal) and left the days from the change date to the cycle end. Credit = old price times left / days. Charge = new price times left / days. Round each to whole cents, halves up. Prices are in cents.
Task: read five lines: cycle start (YYYY-MM-DD), cycle end, change date, old price in cents and new price in cents. If the change date is before the cycle start or on/after the cycle end, print INVALID. Otherwise print three lines Credit: x.xx, Charge: y.yy and Due: z.zz where Due is charge minus credit (it can be negative, print a leading minus sign, for example -25.00).
Sample tests
Input
2026-01-15 2026-02-15 2026-01-25 2900 4900
Expected output
Credit: 19.65 Charge: 33.19 Due: 13.54
Input
2028-02-01 2028-03-01 2028-02-10 1999 3999
Expected output
Credit: 13.79 Charge: 27.58 Due: 13.79
Your answer is also checked against 5 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
