Skip to content
ExamplesEspañolWorkspace →

Data Formatting

Fixes upper and lower case, and converts between text and numbers.

Level
Intermediate
Topic:
Text
Concepts:
Input & output
Text
Open in Codoritmo

Run, change and debug this example in your browser.

What you'll learn

Subcadena, Mayusculas, Minusculas and Concatenar work together to format a name. ConvertirANumero and ConvertirATexto turn data from one type into the other.

Code

text-format.psc · 16 lines
Algoritmo FormatoDeDatos    Definir nombre, apellido, nombreBonito, edadTexto Como Caracter    Definir edad Como Entero    Escribir "Nombre:"    Leer nombre    Escribir "Apellido:"    Leer apellido    Escribir "Edad:"    Leer edadTexto    // Primera letra en mayúscula y el resto en minúscula    nombreBonito <- Concatenar(Mayusculas(Subcadena(nombre, 1, 1)), Minusculas(Subcadena(nombre, 2, Longitud(nombre))))    edad <- ConvertirANumero(edadTexto)    Escribir "Ficha: ", nombreBonito, " ", Mayusculas(apellido)    Escribir "Dentro de 10 años tendrá " + ConvertirATexto(edad + 10) + " años."    Escribir "Letras en el nombre completo: ", Longitud(nombreBonito) + Longitud(apellido)FinAlgoritmo

Flowchart

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

Algoritmo FormatoDeDatosAlgoritmo FormatoDeDatosAlgoritmo FormatoDeDatosDefinir nombre, apellido, nombreBonito, edadTexto Como CaracterDefinir nombre, apellido,nombreBonito, edadTexto ComoCaracterDefinir edad Como EnteroDefinir edad Como EnteroEscribir "Nombre:"Escribir "Nombre:"Leer nombreLeer nombreEscribir "Apellido:"Escribir "Apellido:"Leer apellidoLeer apellidoEscribir "Edad:"Escribir "Edad:"Leer edadTextoLeer edadTextonombreBonito <- Concatenar(Mayusculas(Subcadena(nombre, 1, 1)), Minusculas(Subcadena(nombre, 2, Longitud(nombre))))nombreBonito <-Concatenar(Mayusculas(Subcadena(nombre, 1, 1)),…edad <- ConvertirANumero(edadTexto)edad <-ConvertirANumero(edadTexto)Escribir "Ficha: ", nombreBonito, " ", Mayusculas(apellido)Escribir "Ficha: ",nombreBonito, " ",Mayusculas(apellido)Escribir "Dentro de 10 años tendrá " + ConvertirATexto(edad + 10) + " años."Escribir "Dentro de 10 añostendrá " +ConvertirATexto(edad + 10) +…Escribir "Letras en el nombre completo: ", Longitud(nombreBonito) + Longitud(apellido)Escribir "Letras en el nombrecompleto: ",Longitud(nombreBonito) +…FinAlgoritmoFinAlgoritmo

Sample run

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

Nombre:User answer: lUCÍAApellido:User answer: gómezEdad:User answer: 15Ficha: Lucía GÓMEZDentro de 10 años tendrá 25 años.Letras en el nombre completo: 10

Challenge

Format the last name the same way: first letter uppercase, the rest lowercase.

Show hint

Repeat the nombreBonito line using apellido instead of nombre.

Open in Codoritmo
  • Palindromes

    Checks whether a phrase reads the same forwards and backwards.

    Intermediate
  • Count Vowels

    Counts the vowels, spaces and other characters in a text.

    Intermediate
  • Name Initials

    Gets the initials of a full name.

    Beginner