Below is a program that calculates what stamps I need for a specific value (value entered is in cents! - this might probably easiy be changed: maybe: append "00" to the entered value, get tokens 1 and 2, delimited by a comma and then first two digits of token 2).
So the result is optimized to use the least number of stamps available:
So calling it with 203 returns:
Code: Select all
>stamps 203
1 X D
1 X B
1 X 0,20
1 X 0,05
2 X 0,02
I am sure you experts would optimize it. So that is why I am posting it.
Variable 'stamp' represents stamp value in cents
Variable 'stampd' represents stamp value displayed (because some stamps are marked with letters).
Stamp values are sorted min..max.
Number of stamps available can change so new variables can be added when new stamps are availalbe so the program determines how many variables are defined.
Somehow I just couldn't make it better. I know you know some C (?) shortcuts to get remainders...
Code: Select all
@echo off
REM value;display
REM value in EUR cents!
set stamp[1]=1
set stampd[1]=0,01
set stamp[2]=2
set stampd[2]=0,02
set stamp[3]=5
set stampd[3]=0,05
set stamp[4]=10
set stampd[4]=0,10
set stamp[5]=20
set stampd[5]=0,20
set stamp[6]=40
set stampd[6]=A
set stamp[7]=48
set stampd[7]=B
set stamp[8]=100
set stampd[8]=C
set stamp[9]=126
set stampd[9]=D
REM value in cents
set reqval=%1
if "%1"=="" set /p reqval=Enter required stamp value in EUR cents:
if "%reqval%"=="" echo Enter numeric value^>0&goto :EOF
set /a reqval=reqval * 1
if %reqval% LEQ 0 echo Enter numeric value^>0&goto :EOF
REM get number of tokens
set /a cntmax=1
:00
if defined stamp[%cntmax%] set /a cntmax+=1&goto :00
set /a cntmax-=1
for /L %%L in (%cntmax%,-1,1) do call :11 %%L
goto :EOF
:11
set num=%1
call set stamp_display=%%stampd[%num%]%%
set /a div=reqval/stamp[%num%]
set /a remainder=reqval - stamp[%num%] * div
if not "%div%"=="0" echo %div% X %stamp_display%
set /a reqval=remainder
goto :EOF
Saso