Created
April 17, 2012 04:18
-
-
Save jc245410/2403414 to your computer and use it in GitHub Desktop.
Simple or Compound interest calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Calculate Compound or simple interest | |
% | |
% _____________________ | |
% input data and ---> | calculate interest | -----> output interst | |
% type of interest |_____________________| | |
% | |
% | |
clear | |
clc | |
%simple interest | |
% I = P r t | |
% | |
%compound interest | |
% A = P(1+r)^n | |
% | |
% Outline 1: Ask user whether simple interest or compound interest | |
% | |
interesttype=input('Would you like to calculate 1. Simple interest or 2. Compound interest: '); | |
% First half, which calculates the simple interest. | |
if interesttype == 1; | |
disp('You have chosen simple interest, Please input the following data:') | |
principal = input('Enter the Original amount borrowed or deposited:'); | |
rate = input('Enter the rate of interest:'); | |
time = input('Enter the time:'); | |
% This if statement is used to check whether the rate is enetered | |
% as a integer or decimal and correctly calculates the interest | |
if rate < 1; | |
interest = principal * rate * time; | |
disp('The interest was equal to:') | |
disp(interest) | |
else rate > 1; | |
interest = principal * (rate/100)*time; | |
disp('The interest was equal to:') | |
disp(interest) | |
end | |
%Second half, which is used to calculate the compound interest | |
elseif interesttype ==2 ; | |
disp('You have chosen compound interest, Please input the following data:') | |
principal = input('Enter the Original amount borrowed or deposited:'); | |
rate = input('Enter the rate of interest:'); | |
time = input('Enter the time:'); | |
% This if statement is used to check whether the rate is enetered | |
% as a integer or decimal and correctly calculates the interest | |
if rate < 1; | |
interest = principal *((1 + rate)^time); | |
disp('The interest was equal to:') | |
disp(interest) | |
else rate > 1; | |
interest = principal * ((1 + rate/100)^time); | |
disp('The interest was equal to:') | |
disp(interest) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment