A Monte Carlo simulation of the interactions of cosmic rays with the atmosphere