Re: Re: Now, how about Roman Numerals?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Hugh--

I am very grateful for your help and very impressed with this, but I am not
sure that I am able to confirm that it works and I am not competent to fix
it if it does not. Perhaps you can tell where I am going wrong.

I stored your script as a separate php document, RomanDigit.php. Here is
what I tested it with:

<?php
include ?RomanDigit.php¹;

$a=8;
$b=19;
$c=155;
$d=980;

$ar= IntToRoman($a);
$br= IntToRoman($b);
$cr= IntToRoman($c);
$dr= IntToRoman($d);

echo ³
a = $a and ar = $ar <br>
b = $b and br = $br <br>
c = $c and cr = $cr <br>
d = $d and dr = $dr <br>
²;

?>


And here are the results:

a = 8 and ar = VIII
b = 19 and br = IX 
c = 155 and cr = V 
d = 980 and dr = LXXX

TIA--Dave Shugarts



> function RomanDigit($dig, $one, $five, $ten) {
>   switch($dig) {
>       case 0:    return "";
>       case 1:    return "$one";
>       case 2:    return "$one$one";
>       case 3:    return "$one$one$one";
>       case 4:    return "$one$five";
>       case 5:    return "$five";
>       case 6:    return "$five$one";
>       case 7:    return "$five$one$one";
>       case 8:    return "$five$one$one$one";
>       case 9:    return "$one$ten";
>   }
> }
> 
> function IntToRoman($num) {
>   if (($num < 1) || ($num > 3999))
>       return("No corresponding Roman number!");
> 
>   $m = $num / 1000;
>   $c = ($num % 1000) / 100;
>   $x = ($num % 100) / 10;
>   $i = $num % 10;
> 
>   return(
>        RomanDigit($m, 'M', '', '')
>       .RomanDigit($c, 'C', 'D', 'M')
>       .RomanDigit($x, 'X', 'L', 'C')
>       .RomanDigit($i, 'I', 'V', 'X')
>   );
> }


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux