i wrote some code to generate jobs at intervals of 5,10,25,30 seconds the jobs 5,10,25 can be arrival times of + / - 1 and the arrive time of 30 is + / - 5. the program is working correct in every aspect other than it is going into the negatives. i need a way to stop it from going after the end time. my entime is supose to count down until it reachs 0 or until no programs can be processed. it is running until it goes after 0 so i am getting negative end times. i tried grouping the if and else ifs in whiles to prevent this but that didnt work any input on this would be great thank you.
In your for loop you are updating "endtime." Since you keep subtracting numbers from it, you will eventually go into negatives like you described.
You could try setting the function to create one single job type at a time, and then call the function several times for each type of job you have. Each time you'll pass different parameters, i.e. the specifications for each job, into the function, and it will create jobs based on that.
For example, function parameters could be the base time and change in time for arrival time, like 5 and +/- 1.
Instead of counting end time down you could count up to your end time.
The total arrival time would be time + the random generated number.
Something along the lines like:
create job( arrival time, change in time)
for(time=0; time<end time)
arrival time = time + random number for base with change in time
time = time + arrival base time
Then you just call this function each time for each set of jobs you have with their own time specifications.