Old Russian measure of length: Difference between revisions

→‎{{header|REXX}}: added the REXX language. -- ~~~~
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
Line 18:
100 m = 2249,2971 vershoks = 140,58107 arshins = 46,860366 sazhens = 0,093790712 versts;
3 vershoks = 13,3375 cm; 2 sazhens = 96 vershoks = 6 arshins = 4,268 m; 1 verst = 1,067 km.
 
=={{header|REXX}}==
Program features:
* shows all ''other'' units of measurements when any unit is specified.
* accepts abbreviations of the length units
* does rounding for the two arithmetic operations performed
* does error checking on the user input
* corrects length unit names when not plural
<lang rexx>/*REXX program to read a config file and assign VARs as found within. */
numeric digits 25
vershoks = 2249.2971 / 100
arshins = 140.58107 / 100
sazhens = 46.860366 / 100
versts = 0.093790712 / 100
parse arg N what _ . /*obtain the user's input from CL*/
if N =='' then call err 'no arguments specified.'
if \datatype(N,'N') then call 'units not numeric: ' N
if _\=='' then call err 'too many arguments specified.'
n=n/1 /*normalize it (004──►4 7.──►7)*/
if what=='' then what='meters' /*None specified? Assume meters.*/
parse upper what whatU /*an uppercase version for ABBREV*/
select /*convert the length ───► meters.*/
when abbrev('METERS' ,whatU ) then m=N
when abbrev('VERSHOKS',whatU,2) then m=N / vershoks
when abbrev('ARSHINS' ,whatU ) then m=N / arshins
when abbrev('SAZHENS' ,whatU ) then m=N / sazhens
when abbrev('VERSTS' ,whatU,2) then m=N / versts
otherwise call err 'invalid measure name: ' what
end /*select*/
say n what ' is:'
; if m\=N then say right(m,40) 'meter's(m)
x = m * vershoks ; if rounder(x)\=N then say right(x,40) 'vershok's(x)
x = m * arshins ; if rounder(x)\=N then say right(x,40) 'arshin's(x)
x = m * sazhens ; if rounder(x)\=N then say right(x,40) 'sazhen's(x)
x = m * versts ; if rounder(x)\=N then say right(x,40) 'verst's(x)
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────ERR subroutine─────────────────────────*/
err: say; say; say center(' error! ', max(40, linesize()%2), "*"); say
do j=1 for arg(); say arg(j); say; end; say; exit 13
/*───────────────────────────────ROUNDER subroutine─────────────────────*/
rounder: procedure; parse arg x; _=pos('.',x); if _==0 then return x
parse arg '.' f; return format(x,,length(f)-2) /*handle rounding.*/
/*───────────────────────────────S subroutine───────────────────────────*/
s: if arg(1)=1 then return arg(3); return word(arg(2) 's',1) /*plural*/</lang>
'''output''' when using the input of: <tt> 100 meter </tt>
<pre style="overflow:scroll">
100 meter is:
2249.297100 vershoks
140.5810700 arshins
46.86036600 sazhens
0.09379071200 versts
</pre>
'''output''' when using the input of: <tt> 1.4058107 arshins </tt>
<pre style="overflow:scroll">
1.4058107 arshins is:
1 meter
22.492971 vershoks
1.4058107 arshins
0.46860366 sazhens
0.00093790712 versts
</pre>
'''output''' when using the input of: <tt> -46.860366 sazhens </tt>
<pre style="overflow:scroll">
-46.860366 sazhens is:
-100 meters
-2249.2971 vershoks
-140.58107 arshins
-46.860366 sazhens
-0.093790712 versts
</pre>