Skip to content
ExamplesEspañolWorkspace →

Personal Greeting

Asks for your name and age, and answers with both.

Level
Beginner
Concepts:
Input & output
Variables
Open in Codoritmo

Run, change and debug this example in your browser.

What you'll learn

Definir creates Caracter and Entero variables, and Leer stores what the user types. Escribir can mix text, variables and arithmetic separated by commas.

Code

greeting.psc · 9 lines
Algoritmo Saludo    Definir nombre Como Caracter    Definir edad Como Entero    Escribir "¿Cómo te llamas?"    Leer nombre    Escribir "¿Cuántos años tienes?"    Leer edad    Escribir "Hola, ", nombre, ". El próximo año tendrás ", edad + 1, " años."FinAlgoritmo

Flowchart

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

Algoritmo SaludoAlgoritmo SaludoAlgoritmo SaludoDefinir nombre Como CaracterDefinir nombre Como CaracterDefinir edad Como EnteroDefinir edad Como EnteroEscribir "¿Cómo te llamas?"Escribir "¿Cómo te llamas?"Leer nombreLeer nombreEscribir "¿Cuántos años tienes?"Escribir "¿Cuántos añostienes?"Leer edadLeer edadEscribir "Hola, ", nombre, ". El próximo año tendrás ", edad + 1, " años."Escribir "Hola, ", nombre, ".El próximo año tendrás ", edad+ 1, " años."FinAlgoritmoFinAlgoritmo

Sample run

This is what the program shows when it runs. The answers typed by the user are highlighted.

¿Cómo te llamas?User answer: Ana¿Cuántos años tienes?User answer: 16Hola, Ana. El próximo año tendrás 17 años.

Challenge

Also ask for the current year and work out the year you were born.

Show hint

Define an Entero variable for the year, read it, and subtract the age.

Open in Codoritmo
  • Tip Calculator

    Splits a restaurant bill, tip included.

    Beginner
  • Can I Vote?

    Tells you whether you can vote or how many years you have left.

    Beginner
  • Coffee Shop Menu

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

    Beginner