|
-
April 16th, 2011, 03:56 PM
#1
what is the error: number of pence
what is the error: number of pence
given cents amount $x get number of coins the min can subdivided...
Code:
<?php
// File: example9-9.php
$x = 579;
$a200=0;
$a100=0;
$a50=0;
$a20=0;
$a10=0;
$a5=0;
$a2=0;
$a1=0;
$x1=1;
while ($x1<8) {
switch (true) {
case ($x>=200):
$a200=$x/200-($x%200)/200;
break;
case ($x>=100):
$a100=$x/100-($x%100)/100;
break;
case ($x>=50):
$a50=$x/50-($x%50)/50;
break;
case ($x>=20):
$a20=$x/20-($x%20)/20;
break;
case ($x>=10):
$a10=$x/10-($x%10)/10;
break;
case ($x>=5):
$a5=$x/5-($x%5)/5;
break;
case ($x>=2):
$a2=$x/2-($x%2)/2;
break;
default:
$a1=$x;
break;
}
$x1++ ;
}
echo $a200."x200<br />";
echo $a100."x100<br />";
echo $a50."x50<br />";
echo $a20."x20<br />";
echo $a10."x10<br />";
echo $a5."x5<br />";
echo $a2."x2<br />";
echo $a1."x1<br />";
?>
-
April 16th, 2011, 04:16 PM
#2
Re: what is the error: number of pence
//problem self fixed...
PHP Code:
switch (true) { case ($x>=200): $a200=$x/200-($x%200)/200; $x-=$a200*200; break; case ($x>=100): $a100=$x/100-($x%100)/100; $x-=$a100*100; break; case ($x>=50): $a50=$x/50-($x%50)/50; $x-=$a50*50; break; case ($x>=20): $a20=$x/20-($x%20)/20; $x-=$a20*20; break; case ($x>=10): $a10=$x/10-($x%10)/10; $x-=$a10*10; break; case ($x>=5): $a5=$x/5-($x%5)/5; $x-=$a5*5; break; case ($x>=2): $a2=$x/2-($x%2)/2; $x-=$a2*2; break; default: $a1=$x; break; }
Last edited by PeejAvery; April 16th, 2011 at 04:54 PM.
Reason: Added PHP tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|