For the first day, beg_hr = beg_tip = 0; end_hr = beg_hr + (hrs for first day from data); end_tip = beg_tip + (tips for first day from data). For every day afterwards: beg_hr(current) = end_hr(previous day); beg_tip(current) = end_tip(previous day); end_hr(current) = beg_hr(current) + hrs(current) end_tip(current) = beg_tip(current) + tips(current) This pattern should continue until last day is reached.