MATLAB: For loop to sum up the integer

for loop

here is the question generate a random integer n in the range from 5 to 9 then loop n times to: -prompt the user for an integer between 1 to 10 -print the sum of the numbers entered so far
here what I got:
n = randi([5,9]);
totalsum = 0;
runsum = 0;
for i = n
int = input('Enter an integer between 1 and 10 :');
runsum = runsum + int;
totalsum = runsum + totalsum;
end
I try to call up the loop, like, Enter an integer between 1 and 10 : 8 but it did not countinous to count up the sum
Can anyone have some suggestion for me?

Best Answer

try this:
n = randi([5,9]);
totalsum = 0;
runsum = 0;
for i=1:n
int = input('Enter an integer between 1 and 10 :');
runsum = runsum + int;
totalsum = runsum + totalsum;
end
totalsum
good luck