<?php
function calculate_total ($price, $quantity)
{
$cost = $price * $quantity;
$tax = $cost * (20 / 100);
$total = $cost + $tax;
return $total;
}
?>
<?php
function multiply_3numbers($number1, $number2, $number3)
{
$subtotal = $number1 * $number2;
$total = $subtotal * $number3;
return $total;
}
?>
<?php
$taxp = '25';
function calculate_total2 ($price1, $quantity1)
{
$cost = $price1 * $quantity1;
$tax = $cost * (25 / 100);
$total = $cost + $tax;
return $total;
}
?>
<?php
function multiply_numbers ($number1, $number2)
{
$multiplytotal = $number1 * $number2;
return $multiplytotal;
}
?>
<?php
function write_message1()
{
$message = '"Hello, I am Macintosh."';
return $message;
}
?>
<?php
function image_1()
{
return '<img src="SteveJobs.jpg" alt="image" />';
}
?>
<?php
function link_1()
{
return '<a href="https://www.apple.com">Apple.com</a>';
}
?>
<?php
$tax = '25%';
$tax_rate = 0.25;
function calculate_running_total($price, $quantity)
{
global $tax_rate;
static $running_total = 0;
$total = $price * $quantity;
$tax = $total * $tax_rate;
$running_total = $running_total +$total + $tax;
return $running_total;
}
?>
<?php
function ctap($number1, $number2, $number3, $number4, $number5, $comperable)
{
$step1 = $number1 * $number2 * $number3 * $number4 * $number5;
$step2 = $step1/100;
$total = $step2 * $comperable;
return $total;
}
?>
<?php
function percent_ofnumber ($number, $comperative)
{
$step1 = $comperative/100;
$step2 = $step1 * $number;
return $step2;
}
?>
<?php
function md_p($number1, $number2, $number3, $dby, $comparable)
{
$step1 = $number1 * $number2 * $number3;
$step2 = $step1 / $dby;
$step3 = $step2/100;
$total = $step3 * $comparable;
return $total;
}
?>
<?php
function find_percent($number1, $number2)
{
$subtotal = $number1/$number2;
$total = $subtotal * 100;
return $total;
}
?>
<?php
function multiply_fractions($frac1, $frac2)
{
$stp1 = $frac1 * $frac2;
return $stp1;
}
?>
<?php
function divide_frac($frac1, $frac2)
{
$total = $frac1 / $frac2;
return $total;
}
?>
<?php
function get_stock_message($stock)
{
if ($stock >= 10) {
return 'in stock';
}
if ($stock >0 && $stock <10) {
return 'low stock';
}
return 'out of stock';
}
?>
<?php
function c_c($quantity, $ic, $pd)
{
$subtotal = $ic * $quantity;
$subd = ($subtotal/100) * $pd;
$total = $subtotal - $subd;
return $total;
}
?>
<br>
<center>
<header>
<h2>"Welcome to <?= $coname?>, <?= $name?>."</h2>
</header>
<br>
</center>
<br>
<center>
<article>
<h2>Total cost of buying my overpriced items (after tax):</h2>
<p>Q-tips (3 ind.): $<?= calculate_total(3,5) ?></p>
<p>1 Pencil (with eraser removed): $<?= calculate_total(1,100)?></p>
<p>Used toilet paper (you only need 3 sheets anyway): $<?= calculate_total(3,6)?></p>
<p>*Tax for each item: 20% (in case you can't do math)</p>
</article>
</center>
<center>
<article>
<h1>Multiplying numbers using functions:</h1>
<p>3x5 = <?= multiply_numbers(3,5)?></p>
<p>78x37 = <?= multiply_numbers(78,37)?></p>
<p>65375x345987 = <?= multiply_numbers(65375,345987)?></p>
<p>2427546378530857x281546239856 = <?= multiply_numbers(2427546378530857,281546239856)?></p>
</article>
<article>
<h3>Writing a basic function message:</h3>
<p><?= write_message1()?></p>
</article>
<article>
<h3>Embedding an image function:</h3>
<p><?= image_1()?></p>
</article>
<article>
<h3>Writing a link return function:</h3>
<p><?= link_1()?></p>
</article>
<article>
<h3>Calcutaing more item totals after tax:</h3>
<p>6 books (18.99 each) cost (after tax) - $<?= calculate_total2(18.99,6)?></p>
<p>25 iPhones (14 base) cost (after tax) - $<?= calculate_total2 (799,25)?></p>
<p>30000000000 (3 billion) books (28.99 each) cost (after tax) - $<?= calculate_total2(28.99, 30000000000)?></p>
<p>(the tax for each item is <?=$taxp?>%)</p>
</article>
<article>
<h3>Calculating running total with global and static functions:</h3>
<li><p>6 rare pencils ($3.99 each): $<?= calculate_running_total (3.99, 6)?> (after tax)</p></li>
<li>25 iPhones (14) ($799 each): $<?= calculate_running_total (799, 25)?> (after tax)</p></li>
<li><p>1,000 books ($18.99 each): $<?= calculate_running_total (18.99, 1,000)?> (after tax)</p></li>
<small>Tax = <?=$tax?> (of total)</small>
</article>
<article>
<h2>Finding the total of 3 numbers (multiplied):</h2>
<p>26764 x 3652894 x 3759387 = <?= multiply_3numbers(26764, 3652894, 3759387)?></p>
<p>1312451927465 x 72654872365 x 375638576 = <?= multiply_3numbers (1312451927465, 72654872365, 375638576)?></p>
<p>2463547 x 9732477 x 7235492 = <?= multiply_3numbers (2463547, 9732477, 7235492)?></p>
</article>
<article>
<h2>Calculating value of a percent:</h2>
<p>67% of 2456 = <?= percent_ofnumber(67, 2456)?></p>
<p>6324536% of 2424.5368 = <?= percent_ofnumber(6324536, 2424.5368)?></p>
<p>5641% of 56789 = <?= percent_ofnumber(5641, 56789)?></p>
</article>
<article>
<small><h2>Caclulating the total of 3 numbers (multiplied) pt.2:</h2></small>
<p> 4567 x 67497 x 46743 = <?= multiply_3numbers(4567, 67497, 46743)?></p>
</article>
<article>
<h2>Calculating the total of 5 numbers (multiplied) and then finidng the percent value:</h2>
<p>45% of (2142 x 243245 x 32542355 x 3244 x 242) = <?= ctap(2142, 243245, 32542355, 3244, 242, 45)?></p>
<p>43.756% of (2424 x 324 x 876 x 34763 x 7365) = <?= ctap(2424, 324, 876, 34763, 7365, 43.756)?></p>
<p>36.356% of (23 x 54 x 247 x 242 x 948) = <?= ctap(23, 54, 247, 242, 948, 36.356)?></p>
<p>-5% of (12 x 24 x 89 x 67 x 55) = <?= ctap(12, 24, 89, 67, 55, -5)?></p>
</article>
<article>
<h2>Multiplying 3 numbers together, dividing by another, and finding a comparable percentage value:</h2>
<p>65.371% of ((3654 x 24652 x 2475)/415) = <?= md_p(3654, 24652, 2475, 415, 65.371)?></p>
</article>
<article>
<h2>Calculating percentages:</h2>
<p>What percent is 67 of 756?... <?= find_percent (67, 756)?>%</p>
<p>What percent is 35.673 of 58.937?... <?= find_percent (35.673, 58.937)?>%</p>
<p>What percent is 343.8643 of 47325835?... <?= find_percent(343.8643, 47325835)?>%</p>
<p>What percent is 4324 of 325735?... <?= find_percent(4324, 325735)?>%</p>
</article>
<article>
<h2>Multiplying fractions:</h2>
<p>3/4 x 2/6 = <?= multiply_fractions(3/4, 2/6)?></p>
<p>6/132 x 4/25 = <?= multiply_fractions(6/132, 4/25)?></p>
<p>4/26 x 6/13 = <?= multiply_fractions (4/26, 6/13)?></p>
</article>
<article>
<h2>Dividing fractions (multiplying by the reciprocal):</h2>
<p>(1/2)/(2) = <?= divide_frac(1/2, 2)?></p>
<p>(3/14)/(3/16) = <?= divide_frac(3/14, 3/16)?></p>
<p>(16/81)/(5/4) = <?= divide_frac(16/81, 5/4)?></p>
</article>
<article>
<h2>Multiplying fractions (pt.2):</h2>
<p>5/6078 x 6/7 = <?= multiply_fractions(5/6078, 6/7)?></p>
<p>6/713 x 65/720 = <?= multiply_fractions(6/713, 65/72)?></p>
</article>
<article>
<h2>Returning multiple messages from a function value:(book example):</h2>
<p>Book availability: <?= get_stock_message(25)?></p>
<p>Pencil availability: <?= get_stock_message(5)?></p>
<p>Mug availability: <?= get_stock_message(0)?></p>
</article>
<article>
<h2>Finding total cost with optional discount parameters (book example i made adjustments to):</h2>
<p>Cost of 36 items, each costing $3.99, with a 37.5% discount = $<?= c_c(36, 3.99, 37.5)?></p>
<p> Cost of 360 items, each costing $5.35, with a 43.75% discount = $<?= c_C(360, 5.35, 43.75)?></p>
</article>