I think my answer is not correct for this question, anyone can help me to check it? Thanks

Attached file is the question. Here is my code
B = 10000;
m = 0;
P = input('monthly payment?')
while B>0
B=B*(1.005);
B=B-P
m=m+1
end

 Akzeptierte Antwort

Hi,
It matches with your flowchart, Why do you thing it is not correct?

4 Kommentare

I think the answer should be one answer only not repeatedly.
Erwin,
You're using a while loop, of course you are iterating and you will have multiple stages (you may not wanna call them answer).
Maybe what you're looking for is the final value of m and B. if so then you have to supress them from being showed in MATLAB command windows by terminating them with ;
B = 10000;
m = 0;
P = input('monthly payment?')
while B>0
B=B*(1.005);
B=B-P;
m=m+1;
end
B
m
And just view them after the while loop is finished.
Good, then would you please accept the answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

B = 10000;
m = 0;
P = input('monthly payment?')
while B>0
B=B*(1.005);
B=B-P; %changed
m=m+1; %changed
end
disp(m); %changed

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by