-
-
Save parzibyte/4c5fd899b94bf63a35a4f8b34d8ef978 to your computer and use it in GitHub Desktop.
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
void marcarSalidaVehiculo(struct LugarEstacionamiento lugares[CANTIDAD_CARROS + CANTIDAD_MOTOS], int indice) | |
{ | |
calcularEImprimirInformacionSalida(lugares[indice]); | |
limpiarLugar(&lugares[indice]); | |
} | |
void calcularEImprimirInformacionSalida(struct LugarEstacionamiento lugarEstacionamiento) | |
{ | |
int horasSegunVehiculo = lugarEstacionamiento.horas; | |
double total = 0; | |
double granTotal = 0; | |
double totalExcedente = 0; | |
if (lugarEstacionamiento.tipo == TIPO_CARRO) | |
{ | |
total = horasSegunVehiculo * VALOR_HORA_CARRO; | |
} | |
else | |
{ | |
total = horasSegunVehiculo * VALOR_HORA_MOTO; | |
} | |
time_t ahora = time(NULL); | |
time_t entrada = lugarEstacionamiento.entrada; | |
// Nota: si se quieren hacer pruebas con otras fechas, hay que | |
// cambiar el timestamp a la fecha deseada. Por ejemplo, la siguiente | |
// línea apunta al 10 de marzo de 2022 a las 11:00:00 | |
// time_t entrada = 1646931600; | |
time_t diferencia = ahora - entrada; | |
printf("===========================\n"); | |
printf("Entrada: "); | |
imprimirFechaAPartirDeTimestamp(entrada); | |
printf("\n"); | |
printf("Salida: "); | |
imprimirFechaAPartirDeTimestamp(ahora); | |
printf("\n"); | |
printf("Horas solicitadas: %d\n", horasSegunVehiculo); | |
unsigned long long int horas = diferencia / 60 / 60; | |
diferencia -= 60 * 60 * horas; | |
unsigned long long int minutos = diferencia / 60; | |
diferencia -= 60 * minutos; | |
int conTiempoExtra = 0; | |
if (horas >= horasSegunVehiculo && (((horas - horasSegunVehiculo) * 60) + minutos) >= MINUTOS_EXTRA_PARA_RECARGO) | |
{ | |
conTiempoExtra = 1; | |
totalExcedente = (((horas - horasSegunVehiculo) * 60) + minutos) * VALOR_POR_MINUTO; | |
} | |
granTotal = total + totalExcedente; | |
printf("Tiempo dentro de estacionamiento: "); | |
printf("%llu hora(s) %llu minuto(s) %llu segundo(s)\n", horas, minutos, diferencia); | |
if (conTiempoExtra) | |
{ | |
printf("Tiempo extra: "); | |
printf("%llu hora(s) %llu minuto(s) %llu segundo(s)\n", horas - horasSegunVehiculo, minutos, diferencia); | |
printf("Pago por tiempo extra: %lf\n", totalExcedente); | |
} | |
printf("Placa: %s\n", lugarEstacionamiento.placa); | |
printf("Pago por horas: %0.2lf\n", total); | |
printf("Total: %0.2lf\n", granTotal); | |
printf("===========================\n"); | |
} | |
void limpiarLugar(struct LugarEstacionamiento *lugarEstacionamiento) | |
{ | |
lugarEstacionamiento->entrada = 0; | |
lugarEstacionamiento->estado = DESOCUPADO; | |
lugarEstacionamiento->horas = 0; | |
strcpy(lugarEstacionamiento->placa, ""); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment