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
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: ", otrosFinAlgoritmoFlowchart
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.
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.
Related examples
Caesar Cipher
Encrypts a message by shifting each letter of the alphabet.
AdvancedData Formatting
Fixes upper and lower case, and converts between text and numbers.
IntermediateRoman Numerals
Converts a number from 1 to 3999 into Roman numerals.
Advanced