Personal Greeting
Asks for your name and age, and answers with both.
- Level
- Beginner
- Topic:
- First steps
- 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
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."FinAlgoritmoFlowchart
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.
¿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.
Related examples
Tip Calculator
Splits a restaurant bill, tip included.
BeginnerCan 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