in reply to two dice question
These should have rand(6), rather than rand(5). You need numbers between 1.000... and 6.999... in order for int(rand...) to return numbers between 1 and 6.my $diceone = int(rand(5)) + 1; my $dicetwo = int(rand(5)) + 1;
I would initialize @dicearray more like this:
so it contains the values you need and not the names of variables.my @dicearray = ($dice1,$dice2,$dice3,$dice4,$dice5,$dice6);
That way you can print the selected dice with
instead of the odd foreach loop.print "Rolling first die resulted in : \n"; print $dicearray[$diceone-1]; print "Rolling second die resulted in : \n"; print $dicearray[$dicetwo-1];
|
|---|