forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
Retos/Reto #43 - SIMULADOR DE CLIMA [Fácil]/php/mrf1989.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |