Price fraction: Difference between revisions
Content added Content deleted
(Updated D entry) |
|||
Line 584: | Line 584: | ||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio |
<lang d>import std.stdio; |
||
double priceRounder(double price) |
double priceRounder(in double price) pure nothrow |
||
in { |
|||
assert(price >= 0 && price <= 1.0); |
|||
} body { |
|||
⚫ | |||
enum cin = [.06, .11, .16, .21, .26, .31, .36, .41, .46, .51, |
|||
.56, .61, .66, .71, .76, .81, .86, .91, .96, 1.01]; |
|||
enum cout = [.10, .18, .26, .32, .38, .44, .50, .54, .58, .62, |
|||
⚫ | |||
foreach (i, p; cin) |
|||
foreach (i, p; cin) |
|||
if (p >= price) |
|||
return cout[i]; |
|||
assert(0); |
|||
} |
|||
void main() { |
void main() { |
||
Line 603: | Line 604: | ||
writeln(priceRounder(price)); |
writeln(priceRounder(price)); |
||
}</lang> |
}</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>0.82 |
<pre>0.82 |
||
0.9 |
0.9 |