Old Russian measure of length: Difference between revisions
Old Russian measure of length in various dialects BASIC (BASIC256, Gambas, QBasic, True BASIC, XBasic and Yabasic)
(Added XPL0 example.) |
(Old Russian measure of length in various dialects BASIC (BASIC256, Gambas, QBasic, True BASIC, XBasic and Yabasic)) |
||
Line 516:
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="basic">arraybase 1
dim units = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"}
# all expressed in centimeters
dim convs = {0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000}
do
cls
print
for i = 1 to units[?]
print rjust(string(i),2); " "; units[i]
next
print
do
input "Please choose a unit 1 to 13 : ", unit
until unit >= 1 and unit <= 13
print
do
input "Now enter a value in that unit : ", value
until value >= 0
print
print "The equivalent in the remaining units is : "
print
for i = 1 to units[?]
if i = unit then continue for
print " "; units[i], " : "; value * convs[unit] / convs[i]
next
print
do
input "Do another one y/n : ", yn
yn = lower(yn)
until yn = "y" or yn = "n"
until yn = "n"</syntaxhighlight>
{{out}}
<pre>Same as Run BASIC entry.</pre>
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic">REM >oldrussian
Line 571 ⟶ 607:
2800 liniya
28000 tochka</pre>
==={{header|FreeBASIC}}===
Line 656 ⟶ 693:
Do another one y/n : ? n
</pre>
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim units As String[] = ["tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"]
' all expressed in centimeters
Dim convs As Single[] = [0.254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000]
Dim i, unit As Integer
Dim value As Single
Dim yn As String
Do
Shell("clear")
Print
For i = 1 To units.count
Print Format$(i, "##"); " "; units[i - 1]
Next
Print "\nPlease choose a unit 1 to 13 : "
Do
Input unit
Loop Until unit >= 1 And unit <= 13
Print "\nNow enter a value in that unit : "
Do
Input value
Loop Until value >= 0
Print "\nThe equivalent in the remaining units is : \n"
For i = 0 To units.count - 1
If i = unit - 1 Then Continue 'For
Print units[i]; Space$(10 - Len(units[i]));
Print " : "; value * convs[unit - 1] / convs[i]
Next
Print "\nDo another one y/n : "
Do
Input yn
yn = LCase(yn)
Loop Until yn = "y" Or yn = "n"
Loop Until yn = "n"
End</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">DIM units(1 TO 13) AS STRING
FOR i = LBOUND(units) TO UBOUND(units)
READ units(i)
NEXT i
DATA "tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"
' all expressed in centimeters
DIM convs(1 TO 13) AS SINGLE
FOR i = 1 TO 13
READ convs(i)
NEXT i
DATA 0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000
DIM unit AS INTEGER
DIM value AS SINGLE
DIM yn AS STRING
DO
CLS
PRINT
FOR i = 1 TO 13
PRINT USING "## "; i;
PRINT units(i)
NEXT i
PRINT
DO
INPUT "Please choose a unit 1 to 13 : ", unit
LOOP UNTIL unit >= 1 AND unit <= 13
PRINT
DO
INPUT "Now enter a value in that unit : ", value
LOOP UNTIL value >= 0
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units(i), " : "; value * convs(unit) / convs(i)
NEXT i
PRINT
DO
INPUT "Do another one y/n : ", yn
yn = LCASE$(yn)
LOOP UNTIL yn = "y" OR yn = "n"
LOOP UNTIL yn = "n"</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">DIM units$(1 TO 13)
FOR i = LBOUND(units$) TO UBOUND(units$)
READ units$(i)
NEXT i
DATA "tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"
! all expressed in centimeters
DIM convs(1 TO 13)
FOR i = 1 TO 13
READ convs(i)
NEXT i
DATA 0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000
DO
CLEAR
PRINT
FOR i = 1 TO 13
PRINT USING "## ": i;
PRINT units$(i)
NEXT i
PRINT
DO
INPUT prompt "Please choose a unit 1 to 13 : ": unit
LOOP UNTIL unit >= 1 AND unit <= 13
PRINT
DO
INPUT prompt "Now enter a value! in that unit : ": value
LOOP UNTIL value >= 0
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units$(i), " : "; value*convs(unit)/convs(i)
NEXT i
PRINT
DO
INPUT prompt "Do another one y/n : ": yn$
LET yn$ = LCASE$(yn$)
LOOP UNTIL yn$ = "y" OR yn$ = "n"
LOOP UNTIL yn$ = "n"
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "progname"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
DIM units$[14]
units$[1] = "tochka " : units$[2] = "liniya " : units$[3] = "dyuim "
units$[4] = "vershok " : units$[5] = "piad " : units$[6] = "fut "
units$[7] = "arshin " : units$[8] = "sazhen " : units$[9] = "versta "
units$[10] = "milia " : units$[11] = "centimeter" : units$[12] = "meter "
units$[13] = "kilometer "
' all expressed in centimeters
DIM convs![14]
convs![1] = 0.0254 : convs![2] = 0.254 : convs![3] = 2.54
convs![4] = 4.445 : convs![5] = 17.78 : convs![6] = 30.48
convs![7] = 71.12 : convs![8] = 213.36 : convs![9] = 10668
convs![10] = 74676 : convs![11] = 1 : convs![12] = 100 : convs![13] = 10000
DO
PRINT
FOR i = 1 TO 13
PRINT FORMAT$("##",i); " "; units$[i]
NEXT i
DO
unit = UBYTE(INLINE$("\nPlease choose a unit 1 to 13 : "))
LOOP UNTIL unit >= 1 AND unit <= 13
DO
value = USHORT(INLINE$("\nNow enter a value in that unit : "))
LOOP UNTIL value >= 0
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units$[i], " : "; value * convs![unit] / convs![i]
NEXT i
DO
yn$ = LCASE$(INLINE$("\nDo another one y/n : "))
LOOP UNTIL (yn$ = "y") OR (yn$ = "n")
LOOP UNTIL yn$ = "n"
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
==={{header|Yabasic}}===
<syntaxhighlight lang="basic">dim units$(14)
units$(1) = "tochka" : units$(2) = "liniya" : units$(3) = "dyuim"
units$(4) = "vershok" : units$(5) = "piad" : units$(6) = "fut"
units$(7) = "arshin" : units$(8) = "sazhen" : units$(9) = "versta"
units$(10) = "milia" : units$(11) = "centimeter" : units$(12) = "meter"
units$(13) = "kilometer"
// all expressed in centimeters
dim convs(14)
convs(1) = 0.0254 : convs(2) = 0.254 : convs(3) = 2.54
convs(4) = 4.445 : convs(5) = 17.78 : convs(6) = 30.48
convs(7) = 71.12 : convs(8) = 213.36 : convs(9) = 10668
convs(10) = 74676 : convs(11) = 1 : convs(12) = 100 : convs(13) = 10000
repeat
clear screen
print
for i = 1 to arraysize(units$(), 1) - 1
print i using ("##"), " ", units$(i)
next
print
repeat
input "Please choose a unit 1 to 13 : " unit
until unit >= 1 and unit <= 13
print
repeat
input "Now enter a value in that unit : " value
until value >= 0
print "\nThe equivalent in the remaining units is : \n"
for i = 1 to 13
if i = unit continue
print " ", units$(i), "\t : ", value * convs(unit) / convs(i)
next
print
repeat
input "Do another one y/n : " yn$
yn$ = lower$(yn$)
until yn$ = "y" or yn$ = "n"
until yn$ = "n"
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
=={{header|C}}==
|