MATLAB: How do you finish this for loop? It is telling me to define the variable “total”, but what do I put in order for it to flow with the loop

for loopMATLAB

for i = 1:5
number = input('Enter a number: ');
total = total + number;
end
fprintf('The sum of the numbers is %.2f\n', total);

Best Answer

total=0; % you forgot to intialise total ( to define total before usage)
for i = 1:5
number = input('Enter a number: ');
total = total + number;
fprintf('The sum of the numbers is %.2f\n', total);
end