Price fraction: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 61: | Line 61: | ||
}</lang> |
}</lang> |
||
=={{header|ALGOL 68}}== |
|||
{{trans|C}} - note: This specimen retains the original [[Price Fraction#C|C]] coding style. |
|||
{{works with|ALGOL 68|Revision 1 - no extensions to language used}} |
|||
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}} |
|||
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}} |
|||
<lang algol68>main: |
|||
( |
|||
# Just get a random price between 0 and 1 # |
|||
# srand(time(NIL)); # |
|||
REAL price := random; |
|||
REAL tops := 0.06; |
|||
REAL std val := 0.10; |
|||
# Conditionals are a little odd here "(price-0.001 < tops AND |
|||
price+0.001 > tops)" is to check if they are equal. Stupid |
|||
C floats, right? :) # |
|||
WHILE ( price>tops OR (price-0.001 < tops AND price+0.001 > tops) ) AND tops<=1.01 |
|||
DO |
|||
tops+:=0.05; |
|||
IF std val < 0.26 THEN |
|||
std val +:= 0.08 |
|||
ELIF std val < 0.50 THEN |
|||
std val +:= 0.06 |
|||
ELSE |
|||
std val +:= 0.04 |
|||
FI; |
|||
IF std val > 0.98 THEN |
|||
std val := 1.0 |
|||
FI |
|||
OD; |
|||
printf(($"Value : "g(0,2)l"Converted to standard : "g(0,2)l$, price, std val)) |
|||
)</lang> |
|||
Sample Output: |
|||
<pre> |
|||
Value : .68 |
|||
Converted to standard : .78 |
|||
</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||