total_saving = 0; % iterate through all the 52 weeks in a year for week=1:52 % rand() returns a random number between [0.0 .. 1.0] % multiply it with 25 to have [0.0 .. 25.0] range saving_this_week = rand() * 25; % accumulate the saving so far total_saving = total_saving + saving_this_week; end disp(total_saving);