is115-php/modul1/index1_4.php

48 lines
1.1 KiB
PHP

<?php include '../common.php'; ?><!DOCTYPE html>
<html lang="no">
<head>
<title><?=title();?></title>
<link rel="stylesheet" href="../index.css">
<style>
input[type=number] {
width: 50px;
}
</style>
</head>
<body>
<div class="container">
<h1><?=title();?></h1>
<h4><?=getNavigation();?></h4>
<h2>Liten kalkulator</h2>
<div>
<?php
$tall1 = $_GET['t1'] ?? random_int(1,100);
$tall2 = $_GET['t2'] ?? random_int(1,100);
$sum = $tall1+$tall2;
$diff = higher($tall1, $tall2) - lower($tall2, $tall1);
$avg = ($tall1+$tall2)/2;
?>
<p>Tallene <?=$tall1;?> og <?=$tall2;?> blir totalt <code><?=$sum;?></code>, differenserer <code><?=$diff;?></code> og har gjennomsnitt <code><?=$avg;?></code></p>
<br>
<form action="index1_4.php">
<p>
<input type="number" name="t1" value="<?=$tall1;?>">
<input type="number" name="t2" value="<?=$tall2;?>">
<input type="submit" value="Kalkuler...">
</p>
</form>
</div>
</div>
</body>
</html>