Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB program named whileadder , to Input a desired maximum value. Be s

ID: 3760861 • Letter: W

Question

Write a MATLAB program named whileadder , to

Input a desired maximum value. Be sure it is one value only

Compute a running total by ones

Return as output the last integer that can be added before the total exceeds max

For example, if input max = 60, the output should = 10, because 1+2+3+4+5+6+7+8+9+10 = 55 and adding 11 would make the sum > 60. If max = 55, then the output would be = 10.

The problem I have is not getting the output number to be correct. So when I enter the max to be 60, the number 11 is the output I keep getting. The output I need is 10. How do I achieve this?

Explanation / Answer

n = input('Enter the maximum value: ');

sum = 0;

i = 1;

while(sum + i <= n)

   sum = sum + i;

   i = i + 1;

end

display(i-1)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote