Skip to content
ExamplesEspañolWorkspace →

Count Vowels

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

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

Run, change and debug this example in your browser.

What you'll learn

A Para loop reads the text letter by letter with Subcadena. Segun accepts several values in one case, like "a", "e", "i", "o", "u".

Code

count-vowels.psc · 23 lines
Algoritmo ContarVocales    Definir texto, letra Como Caracter    Definir i, vocales, espacios, otros Como Entero    Escribir "Escribe un texto:"    Leer texto    vocales <- 0    espacios <- 0    otros <- 0    Para i <- 1 Hasta Longitud(texto) Hacer        letra <- Minusculas(Subcadena(texto, i, i))        Segun letra Hacer            "a", "e", "i", "o", "u":                vocales <- vocales + 1            " ":                espacios <- espacios + 1            De Otro Modo:                otros <- otros + 1        FinSegun    FinPara    Escribir "Vocales: ", vocales    Escribir "Espacios: ", espacios    Escribir "Otros caracteres: ", otrosFinAlgoritmo

Flowchart

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

Algoritmo ContarVocales"a", "e", "i", "o", "u"" "De Otro ModoAlgoritmo ContarVocalesAlgoritmo ContarVocalesDefinir texto, letra Como CaracterDefinir texto, letra ComoCaracterDefinir i, vocales, espacios, otros Como EnteroDefinir i, vocales, espacios,otros Como EnteroEscribir "Escribe un texto:"Escribir "Escribe un texto:"Leer textoLeer textovocales <- 0vocales <- 0espacios <- 0espacios <- 0otros <- 0otros <- 0Para i <- 1 Hasta Longitud(texto) HacerPara i <- 1 HastaLongitud(texto)letra <- Minusculas(Subcadena(texto, i, i))letra <-Minusculas(Subcadena(texto, i,i))Segun letra Hacerletravocales <- vocales + 1vocales <- vocales + 1espacios <- espacios + 1espacios <- espacios + 1otros <- otros + 1otros <- otros + 1Escribir "Vocales: ", vocalesEscribir "Vocales: ", vocalesEscribir "Espacios: ", espaciosEscribir "Espacios: ",espaciosEscribir "Otros caracteres: ", otrosEscribir "Otros caracteres: ",otrosFinAlgoritmoFinAlgoritmo

Sample run

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

Escribe un texto:User answer: Programar es pensarVocales: 6Espacios: 2Otros caracteres: 11

Challenge

Also count accented vowels (á, é, í, ó, ú) as vowels.

Show hint

Add those letters to the list in the vowel case.

Open in Codoritmo
  • Caesar Cipher

    Encrypts a message by shifting each letter of the alphabet.

    Advanced
  • Data Formatting

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

    Intermediate
  • Roman Numerals

    Converts a number from 1 to 3999 into Roman numerals.

    Advanced