[EMAIL PROTECTED] wrote:
Hi, Members
The script below produce an error at the printf function at line 342 which says "Illegal division by zero at \perl\baccarat.pl line 342.".
Can someone tell me whats wrong.
Thanks
====partial script===================
my $total = $banker_counter + $player_counter;
open (BACCARAT_DATA,">>BACCARAT_DATA.txt") || die $!;
print BACCARAT_DATA "\n";
# the error starts here which is line 342
printf BACCARAT_DATA "Total: Banker = $banker_counter (%2.0f%%), Player =
$player_counter (%2.0f%%),".
" Tie = $draw_counter (%2.0f%%).\n",
(($banker_counter / $total) * 100) ,
(($player_counter / $total) * 100) ,
(($draw_counter / ( $banker_counter + $player_counter + $draw_counter )) * 100 );
In addition to what yitzle and Joshua said, your printf format would be
better as:
printf BACCARAT_DATA "Total: Banker = %s (%2.0f%%), Player = %s
(%2.0f%%), Tie = %s (%2.0f%%).\n",
$banker_counter,
( $banker_counter / $total ) * 100,
$player_counter,
( $player_counter / $total ) * 100,
$draw_counter,
( $draw_counter / ( $banker_counter + $player_counter +
$draw_counter ) ) * 100;
Also the format "%2.0f" says to print the argument as a floating point
number but not print the "floating point" part which is effectively the
same as printing the argument as an integer using "%2d".
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/