termination of code
| Themba (2) | |||
| #include <iostream> #include <math.h> #include<time.h> #include <fstream> using namespace std; float randNum() { float x,y,r; x = rand(); y = RAND_MAX; r = x/y; return r; } int main () { ofstream fileout(" themba.csv") ; // Varaible Declaration int i=1,num,mL,mD,mW,count=0,N=1; cout<<"please enter total number of arrival jobs:"<<endl; cin>>num; float t,tL,D_proctime,t_sim,simulation_t[i],depart_time[count],R,diff,currenttime=0,nextdepaturet,nextarrivalt,QueueL=0; float q,pL,pD,A=0,B=0,D,array[num] ,arrayL[num],arrivalD[count],arrivalW[count],arraytotL,arrayTot; //INPUTS// cout<<"please enter arrival rate:"<<endl; cin>>q; cout<<"please enter total number lathe machines:"<<endl; cin>>mL; cout<<"Please enter processing rate for lathe: "<<endl; cin>>pL; while (i<num) { // arrival time for cutting department t=(log(randNum()))/(-q); A=A +t; array[i]=A; cout<<"arrival t= \t"<<array[i]<<endl; // processing time for lathes if (( N>=1)&&(N<=mL)) { tL=(log(randNum()))/(-N*pL); B=B +tL; arrayL[i] =B; cout<<"proc time= \t"<<arrayL[i]<<endl; } else if ( N>mL) { tL=(log(randNum()))/(-mL*pL); B=B +tL; arrayL[i] =B; cout<<"proc time= \t"<<arrayL[i]<<endl; } //Simualtionn for number of jobs in the cuuting department diff=(tL-t); // comparing the interarrival time with processing time t_sim=t_sim+tL; // this is simulation time of the cutting department simulation_t[i]=t_sim; if ( diff<0) { N=N+1; // increament increasing the # of job in the system cout<<"N= \t"<<N<<endl; simulation_t[i-1]=array[i]; } else if(diff>0) { N=N-1; cout<<"N= \t"<<N<<endl; depart_time[count]=simulation_t[i-1]; // storing the departure time in array for further use count=count+1; } else { N=N; cout<<"N= \t"<<N<<endl; } i=i+1; QueueL=(N-mL); cout<<"Queue length= \t"<<QueueL<<endl; fileout<<arrayL[i]<<","<<N<<","<<QueueL<<","<<endl; } for ( count=0; count<num ;count++) { R=randNum(); if ( R<0.3) { arrivalW[count]=depart_time[count]; cout<<" welding arrival_t= \t"<<arrivalW[count]<<endl; } else { arrivalD[count]=depart_time[count]; cout<<" drilling arrival_t= \t"<< arrivalD[count]<<endl; } } return 0; My problem is this code terminate when there is large input value for "num" and the first csv output don't correspond with the variable "arrayL[i]" | |||
| Themba (2) | |||
My problem is this code terminate when there is large input value for "num" and the first csv output don't correspond with the variable "arrayL[i]" on the code below#include <iostream> #include <math.h> #include<time.h> #include <fstream> using namespace std; float randNum() { float x,y,r; x = rand(); y = RAND_MAX; r = x/y; return r; } int main () { ofstream fileout(" themba.csv") ; // Varaible Declaration int i=1,num,mL,mD,mW,count=0,N=1; cout<<"please enter total number of arrival jobs:"<<endl; cin>>num; float t,tL,D_proctime,t_sim,simulation_t[i],depart_time[count],R,diff,currenttime=0,nextdepaturet,nextarrivalt,QueueL=0; float q,pL,pD,A=0,B=0,D,array[num] ,arrayL[num],arrivalD[count],arrivalW[count],arraytotL,arrayTot; //INPUTS// cout<<"please enter arrival rate:"<<endl; cin>>q; cout<<"please enter total number lathe machines:"<<endl; cin>>mL; cout<<"Please enter processing rate for lathe: "<<endl; cin>>pL; while (i<num) { // arrival time for cutting department t=(log(randNum()))/(-q); A=A +t; array[i]=A; cout<<"arrival t= \t"<<array[i]<<endl; // processing time for lathes if (( N>=1)&&(N<=mL)) { tL=(log(randNum()))/(-N*pL); B=B +tL; arrayL[i] =B; cout<<"proc time= \t"<<arrayL[i]<<endl; } else if ( N>mL) { tL=(log(randNum()))/(-mL*pL); B=B +tL; arrayL[i] =B; cout<<"proc time= \t"<<arrayL[i]<<endl; } //Simualtionn for number of jobs in the cuuting department diff=(tL-t); // comparing the interarrival time with processing time t_sim=t_sim+tL; // this is simulation time of the cutting department simulation_t[i]=t_sim; if ( diff<0) { N=N+1; // increament increasing the # of job in the system cout<<"N= \t"<<N<<endl; simulation_t[i-1]=array[i]; } else if(diff>0) { N=N-1; cout<<"N= \t"<<N<<endl; depart_time[count]=simulation_t[i-1]; // storing the departure time in array for further use count=count+1; } else { N=N; cout<<"N= \t"<<N<<endl; } i=i+1; QueueL=(N-mL); cout<<"Queue length= \t"<<QueueL<<endl; fileout<<arrayL[i]<<","<<N<<","<<QueueL<<","<<endl; } for ( count=0; count<num ;count++) { R=randNum(); if ( R<0.3) { arrivalW[count]=depart_time[count]; cout<<" welding arrival_t= \t"<<arrivalW[count]<<endl; } else { arrivalD[count]=depart_time[count]; cout<<" drilling arrival_t= \t"<< arrivalD[count]<<endl; } } return 0; | |||
| Dirtrider (15) | |||
| |||
This topic is archived - New replies not allowed.
