So I want to be able to find the dividend from a stock. I've managed to do it in a simple way, but this time, I want to do it using a recursive routine. I can't seem to figure out how to do this. But anyway, here's the original script along with a few miserable attempts.
Thanks for the help in advance!use warnings; print "A stock xyz's price is now $100. It has 3.78% dividend. You hav +e 1000 of it and reinvest the dividend into the stock.\n"; my %hash; @stocknum = 1000; @dividend = 6780; while ($#dividend != 20) { $a = $dividend[-1]; $stock = $stocknum[-1]; $div_total= $stock*100*0.0678; $stock_total = $stock + int($a/100); push (@stocknum, $stock_total); push (@dividend, $div_total); if ($#dividend == 20) { last; } } dividend (@dividend); sub dividend { @new = shift; $stock_num = $stocknum[-1]; $div = $stock_num*100*0.0678; push (@_, $div); @hash{@stocknum} = @_; foreach $key(sort keys %hash) { print "Stock number: $key\t"."Dividend: $hash{$key}\n"; } } $dividend=0.0378;
In reply to dividend with recursive routine by derpp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |