Price fraction: Difference between revisions

Added Commodore BASIC
(Added Commodore BASIC)
Line 357:
.3444635 .5
.0491907 .1
 
==={{header|Commodore BASIC}}===
 
We'll use a couple of arrays for translation. Should work for several other 8-bit BASICs after converting the screen control codes.
 
<lang gwbasic>1 rem price fraction
2 rem rosetta code
10 data 0.06,0.1,0.11,0.18,0.16,0.26,0.21,0.32,0.26,0.38,0.31,0.44,0.36,0.5
20 data 0.41,0.54,0.46,0.58,0.51,0.62,0.56,0.66,0.61,0.70,0.66,0.74,0.71,0.78
30 data 0.76,0.82,0.81,0.86,0.86,0.90,0.91,0.94,0.96,0.98,1.01,1.0
35 rem up=user price, th=threshold, pr=price, np=new price
40 dim th(20),pr(20):th(0)=0:pr(0)=0
45 for i=1 to 20:read th(i),pr(i):next
50 print chr$(147);chr$(14);"Price Fraction":print
60 print "What is the value to calculate (between 0.0 and 1.0)";:input up
65 if up<0 or up>1.0 then goto 60
70 gosub 500
80 print:print "You entered";up;chr$(157);", the new value is";np
90 print:print "Again (Y/N)? ";
95 get k$:if k$<>"y" and k$<>"n" then 95
100 print k$
110 if k$="y" then goto 50
115 end
500 for i=0 to 20
510 if up<th(i) then np=pr(i):return
520 next i
530 np=1:return
</lang>
 
{{out}}
<pre>Price Fraction
 
What is the value to calculate (between 0.0 and 1.0)? 0.83344
 
You entered .83344, the new value is .9
 
Again (Y/N)? Y</pre>
 
<pre>Price Fraction
 
What is the value to calculate (between 0.0 and 1.0)? 0.05889
 
You entered .05889, the new value is .1
 
Again (Y/N)? Y</pre>
 
<pre>Price Fraction
 
What is the value to calculate (between 0.0 and 1.0)? 0.36
 
You entered .36, the new value is .54
 
Again (Y/N)? N
ready.</pre>
 
=={{header|BBC BASIC}}==
113

edits