Skip to content

Commit

Permalink
Merge pull request #5617 from mrf1989/main
Browse files Browse the repository at this point in the history
Reto #43 - PHP
  • Loading branch information
Roswell468 authored Oct 31, 2023
2 parents 1412b1d + 028cd99 commit 4b54d29
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Retos/Reto #43 - SIMULADOR DE CLIMA [Fácil]/php/mrf1989.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

function predecir_clima(int $dias, int $tmp_inicial, int $p_lluvia_inicial): void
{
$tmp = $tmp_inicial;
$p_lluvia = $p_lluvia_inicial;
$dias_lluviosos = 0;
$tmp_diarias = array($tmp_inicial);

for ($i = 1; $i <= $dias; $i++) {
echo "Día {$i}\n";
echo "La probabilidad de lluvia es del {$p_lluvia}%\n";

$cambio = rand(0, 100);

if ($cambio <= 10) {
$subida = rand(0, 1);

if ($subida) {
$tmp += 2;
} else {
$tmp -= 2;
}
}

echo "La temperatura es de {$tmp} grados.\n";
array_push($tmp_diarias, $tmp);

if ($p_lluvia == 100) {
$dias_lluviosos++;
}


if ($tmp > 25) {
$p_lluvia += 20;
if ($p_lluvia > 100) {
$p_lluvia = 100;
$tmp -= 1;
}
} else if ($tmp < 5) {
$p_lluvia -= 20;
if ($p_lluvia < 0) {
$p_lluvia = 0;
}
}
}

echo "RESUMEN:\n";
echo "- Días lluviosos: {$dias_lluviosos}.\n";
echo "Temperatura máxima: " . max($tmp_diarias) . " grados.\n";
echo "Tempratura mínima: " . min($tmp_diarias) . " grados.\n";
}

predecir_clima(24, 24, 20);

0 comments on commit 4b54d29

Please sign in to comment.