% Script to add a series of user input values
% Make sure we are starting clean
clear
% Initialize the accumulation variable
total = 0;
% Get the number of values to be added
n = input('Input number of values: ');
% Begin main accumulation loop
for i = 1:n
% Ask user for the next value
value = input('Input next value : ');
% Add this new value into the existing total
total = total + value;
% If we want to compute a running average, we can add this in the
% body of the loop. Here, we divide by i because we want to divide
% total by the number of values input to this point in the loop.
avg = total/i
end
% Display results
disp('Total sum = ')
total
% Compute the average of the net sum
disp('average = ')
avg = total/n