a code that compute numbers and numbers does not !
조회 수: 1 (최근 30일)
이전 댓글 표시
greetings all,
the following code I've created to compute an amount. whenever I try number of years let's say 2 it will compute correctly. However, when I want to compute something like 10 years it wont work ! please can you adivse
p = input('enter the amount you want to deposit initially:');
n = input('enter number of years:');
t = input(['enter the frequency of interest compounding\n'...
'type 1: for annually\n'...
'type 2: for semi annually\n'...
'type 4: for quarterly\n'...
'type 12: for monthly\n']);
r = input('enter the interest rate:');
switch n
case (1)
a = p*((1+((0.01*r)/t))^(n*t));
disp(['annually:',num2str(a)]);
case (2)
a = p*((1+((0.01*r)/t))^(n*t));
disp(['semi annually:',num2str(a)]);
case (4)
a = p*((1+((0.01*r)/t))^(n*t));
disp(['quarterly:',num2str(a)]);
case (12)
a = p*((1+((0.01*r)/t))^(n*t));
disp(['monthly:',num2str(a)]);
end
댓글 수: 0
답변 (1개)
Sreedhar Arumugam
2021년 9월 15일
I am assuming you want to compute interest based on the frequency of compounding.
Your switch statement is with respect to n (number of years) when it should actually be with respect to t (frequency of compounding).
switch t
case(1)
case (2)
case (4)
case(12)
end
This is why it fails for n=10 in your code as there is no case corresponding for this input.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!