Parking Fee
Charges every started hour, with a daily maximum.
- Level
- Intermediate
- Topic:
- Decisions
- Concepts:
- Input & output
- Si
- Math
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Trunc and MOD split full hours from the leftover minutes. A few Si blocks in a row apply the rate and the daily cap.
Code
Algoritmo TarifaEstacionamiento Definir minutos, horas Como Entero Definir costo Como Real Escribir "¿Cuántos minutos estuvo el auto?" Leer minutos // Cada hora empezada se cobra completa horas <- Trunc(minutos / 60) Si minutos MOD 60 > 0 Entonces horas <- horas + 1 FinSi Si horas = 0 Entonces costo <- 0 SiNo Si horas = 1 Entonces costo <- 20 SiNo costo <- 20 + (horas - 1) * 15 FinSi FinSi Si costo > 120 Entonces costo <- 120 Escribir "Se aplicó la tarifa máxima diaria." FinSi Escribir "Horas cobradas: ", horas Escribir "Total a pagar: $", costoFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
¿Cuántos minutos estuvo el auto?User answer: 135Horas cobradas: 3Total a pagar: $50
Challenge
Add a grace period: cars that stay 15 minutes or less park for free.
Show hint
Check minutos <= 15 first and set the cost to 0 in that case.
Related examples
Quadratic Equation
Solves ax² + bx + c = 0, with real or complex roots.
IntermediateCan I Vote?
Tells you whether you can vote or how many years you have left.
BeginnerCoffee Shop Menu
Pick a drink from the menu and get the total to pay.
Beginner