Skip to content
ExamplesEspañolWorkspace →

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

can-vote.psc · 10 lines
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."    FinSiFinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo PuedeVotarSíNoAlgoritmo PuedeVotarAlgoritmo PuedeVotarDefinir edad Como EnteroDefinir edad Como EnteroEscribir "¿Qué edad tienes?"Escribir "¿Qué edad tienes?"Leer edadLeer edadSi edad >= 18 Entoncesedad >= 18Escribir "Ya puedes votar."Escribir "Ya puedes votar."Escribir "Todavía no puedes votar. Te faltan ", 18 - edad, " años."Escribir "Todavía no puedesvotar. Te faltan ", 18 - edad," años."FinAlgoritmoFinAlgoritmo

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.

Open in Codoritmo
  • Coffee Shop Menu

    Pick a drink from the menu and get the total to pay.

    Beginner
  • Parking Fee

    Charges every started hour, with a daily maximum.

    Intermediate
  • Leap Year

    Applies the calendar rules to tell whether a year is a leap year.

    Intermediate