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 Pascal

1 Answer

0 votes
program CompoundInterestCalculator;

uses
  Math; // Power

var
  Principal, Rate, Years, Amount, Interest: Real;

function CalculateCompoundInterest(P, R, T: Real): Real;
begin
  if (P < 0) or (R < 0) or (T < 0) then
  begin
    Writeln('Error: Principal, rate, and years must be non-negative values.');
    CalculateCompoundInterest := -1;
  end
  else
  begin
    // Calculate total amount using the compound interest formula
    Amount := P * Power(1 + R / 100, T);
    
    // Return compound interest
    CalculateCompoundInterest := Amount - P;
  end;
end;

begin
  Principal := 100000;
  Rate := 3.5;
  Years := 5;

  Interest := CalculateCompoundInterest(Principal, Rate, Years);

  if Interest >= 0 then
  begin
    Writeln('Principal Amount: ', Principal:0:2);
    Writeln('Annual Interest Rate: ', Rate:0:2, '%');
    Writeln('Years: ', Years:0:2);
    Writeln('Compound Interest: ', Interest:0:2);
    Writeln('Total Amount: ', (Principal + Interest):0:2);
  end;
end.




(*
run:

Principal Amount: 100000.00
Annual Interest Rate: 3.50%
Years: 5.00
Compound Interest: 18768.63
Total Amount: 118768.63

*)





answered Aug 30, 2025 by avibootz
edited Aug 30, 2025 by avibootz

Related questions

1 answer 57 views
1 answer 46 views
1 answer 57 views
1 answer 63 views
1 answer 50 views
...