Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to calculate compound interest in VB.NET

1 Answer

0 votes
Imports System

Class CompoundInterestCalculator
    Private Shared Function CalculateCompoundInterest(ByVal principal As Double, ByVal rate As Double, ByVal years As Double) As Double
        If principal < 0 OrElse rate < 0 OrElse years < 0 Then
            Console.WriteLine("Error: Principal, rate, and years must be non-negative values.")
            Return -1
        End If
		
		' Calculate total amount using the compound interest formula
        Dim amount As Double = principal * Math.Pow(1 + rate / 100, years)
		
		' Return compound interest
        Return amount - principal
    End Function

    Public Shared Sub Main()
        Dim principal As Double = 100000
        Dim rate As Double = 3.5
        Dim years As Double = 5
        Dim interest As Double = CalculateCompoundInterest(principal, rate, years)

        If interest >= 0 Then
            Console.WriteLine($"Principal Amount: {principal}")
            Console.WriteLine($"Annual Interest Rate: {rate}%")
            Console.WriteLine($"Years: {years}")
            Console.WriteLine($"Compound Interest: {interest}")
            Console.WriteLine($"Total Amount: {(principal + interest)}")
        End If
    End Sub
End Class



' run:
'
' Principal Amount: 100000
' Annual Interest Rate: 3.5%
' Years: 5
' Compound Interest: 18768.630564687453
' Total Amount: 118768.63056468745
' 

 



answered Aug 30, 2025 by avibootz

Related questions

...