Can I Vote?
Tells you whether you can vote or how many years you have left.
- Level
- Beginner
- Topic:
- Decisions
- Concepts:
- Input & output
- Si
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Your first decision with Si ... Entonces ... SiNo ... FinSi. The condition edad >= 18 picks which of the two paths runs.
Code
Algoritmo PuedeVotar Definir edad Como Entero Escribir "¿Qué edad tienes?" Leer edad Si edad >= 18 Entonces Escribir "Ya puedes votar." SiNo Escribir "Todavía no puedes votar. Te faltan ", 18 - edad, " años." FinSiFinAlgoritmoFlowchart
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.
¿Qué edad tienes?User answer: 16Todavía no puedes votar. Te faltan 2 años.
Challenge
If the age is negative, print "That age is not valid".
Show hint
Add a check for edad < 0 before the other conditions.
Related examples
Coffee Shop Menu
Pick a drink from the menu and get the total to pay.
BeginnerParking Fee
Charges every started hour, with a daily maximum.
IntermediateLeap Year
Applies the calendar rules to tell whether a year is a leap year.
Intermediate