Compound Interest
Watch your savings grow year by year.
- Level
- Intermediate
- Topic:
- Math
- Concepts:
- Input & output
- Para
- Math
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
A Para loop applies the interest to the running amount on each pass. Ln works out how long it takes to double your money, and Exp gives the result with continuous interest.
Code
Algoritmo InteresCompuesto Definir capital, tasa, monto Como Real Definir anios, i Como Entero Escribir "Capital inicial:" Leer capital Escribir "Interés anual (%):" Leer tasa Escribir "Años:" Leer anios monto <- capital Para i <- 1 Hasta anios Hacer monto <- monto * (1 + tasa / 100) Escribir "Año ", i, ": $", Redon(monto * 100) / 100 FinPara Escribir "Ganancia total: $", Redon((monto - capital) * 100) / 100 Si tasa > 0 Entonces Escribir "Años para duplicar el capital: ", Redon(Ln(2) / Ln(1 + tasa / 100) * 10) / 10 FinSi Escribir "Con interés continuo serían: $", Redon(capital * Exp(tasa / 100 * anios) * 100) / 100FinAlgoritmoFlowchart
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.
Capital inicial:User answer: 10000Interés anual (%):User answer: 8Años:User answer: 5Año 1: $10800Año 2: $11664Año 3: $12597.12Año 4: $13604.89Año 5: $14693.28Ganancia total: $4693.28Años para duplicar el capital: 9Con interés continuo serían: $14918.25
Challenge
Add a fixed deposit that is added at the end of every year.
Show hint
Read the deposit before the loop and add it to monto after applying the interest.
Related examples
Prime Numbers
Finds every prime number up to a limit.
IntermediateFibonacci Sequence
Prints the first terms of the Fibonacci sequence.
BeginnerCaesar Cipher
Encrypts a message by shifting each letter of the alphabet.
Advanced