Stock Market Average Calculator

Stock Market Average Calculator

Purchase 1

Purchase 2

'; echo '

Results

'; for ($i = 0; $i < count($units); $i++) { $purchaseAmount = $units[$i] * $prices[$i]; $totalShares += $units[$i]; $totalAmount += $purchaseAmount; echo "

Purchase " . ($i+1) . ": " . $units[$i] . " shares at $" . number_format($prices[$i], 2) . " = $" . number_format($purchaseAmount, 2) . "

"; } if ($totalShares > 0) { $averagePrice = $totalAmount / $totalShares; echo "

Total Shares: " . number_format($totalShares, 2) . "

"; echo "

Total Invested: $" . number_format($totalAmount, 2) . "

"; echo "

Average Cost Per Share: $" . number_format($averagePrice, 2) . "

"; } else { echo "

Please enter valid purchase information.

"; } echo '
'; } ?>

No comments:

Post a Comment