simply_vheng 0 Newbie Poster

i need some guide..
i'm a new member here.
this is my first time to ask for help.

i've been working for this code for two days..
but i cant find way to make it better..huhu
it suppose to do a "round robin with overhead".
its an algorithm..

i think, its not new for all of you.
i hope you have some background about this topic.
(cpu scheduling..),..

would you please help me??

all i need is to avoid duplication of arrival time for each job..
huhu.
when you enter the arrival time for each job,
its arrival time will be na name or the number of the job..

..please compile it..to understand it more.
hmmmm,
for some one who will help me,
it will be fully appreciated..
thank you..wink♥_+)v

#include<stdio.h>
#include<conio.h>

void main()
{
struct job{
int at;
int bt;
};
struct job J[80], cpy[80], temp, cpy2[80];
int q,qq,oh, jbn, x, y, z, t, ref=0, tt[80],ttave=0,wtave=0;
again:
clrscr();
textcolor(YELLOW);
gotoxy(20,5); cprintf("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*");
gotoxy(20,6); cprintf("*~* ROUND ROBIN WITH OVERHEAD ALGORITHM *~*");
gotoxy(20,7); cprintf("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*");
textcolor(10);
gotoxy(5,8); cprintf("Enter number of jobs(not more than 15 jobs)   ");
scanf("%d", &jbn);
if(jbn>15)
{
printf("\tWrong input!! just enter maximum of 15 jobs!\n");
printf("\tPress enter");
getch();
goto again;}
else
{
gotoxy(10,9); printf("Enter corresponding arrival time and burst time");
gotoxy(15,11); printf("Job          Arrival time          Burst time");
y=11;
for(x=1;x<=jbn;x++)
{y=y+2;
 gotoxy(16,y);printf("J%d",x);
 gotoxy(33,y); scanf("%d",&J[x-1].at);
 gotoxy(54,y); scanf("%d",&J[x-1].bt);}//end for
y=y+2;
gotoxy(10,y); printf("Please enter quantum time:\t");
scanf("%d",&q);
y=y+2;
gotoxy(10,y); printf("Please enter overhead time:\t");
scanf("%d",&oh);
y=y+2;
gotoxy(10,y);
puts("Datas have been processed. Just press enter...");
getch();
for(x=0;x<jbn;x++)
{cpy[x].at=J[x].at;
 cpy[x].bt=J[x].bt;}
for(x=jbn-1;x>=0;x--)
 {for(z=1;z<=x;z++)
    {if(cpy[x].at<cpy[x-z].at)
       {temp.at=cpy[x].at;
	temp.bt=cpy[x].bt;
	cpy[x].at=cpy[x-z].at;
	cpy[x].bt=cpy[x-z].bt;
	cpy[x-z].at=temp.at;
	cpy[x-z].bt=temp.bt;}//end if
      }//end for1
 }//end for2
printf("\n");

x=0;
t=0;ref=0;



while(x<jbn)
{
 if(t<cpy[x].at)
  {
   t=cpy[x].at;
   ref=t;

  }

 else if(t>=cpy[x].at)
  {
   t+=cpy[x].bt;
   ref=t;
   x++;

  }
};

printf("%d",ref);

for(x=0;x<jbn;x++)
{cpy2[x].at=cpy[x].at;
 cpy2[x].bt=cpy[x].bt;}
x=0;
printf("Gantt Chart:\n\n");
/*for(t=0;t<=ref;t++)
  {textcolor(10);
   cprintf("|");
   z=0;
   while(cpy[x].at!=J[z].at&&cpy[x].bt!=J[z].bt)
     z++;
   printf(" J%d (%d)",z+1,J[z].bt);
   t=t+J[z].bt;
   tt[x]=t;
   t--;
   x++;}*/

printf("0  |");

x=0;
t=0;

 int t2=0,t3;
 if(cpy[0].at!=0)
	printf("I  (%d) | %d     ",cpy[0].at,cpy[0].at);
 while(t<=ref-oh)
  {t3=t;
   for(x=0;x<jbn;x++)
	{z=0; if(t==cpy2[x].at)
	    {
	       if(q>=cpy2[x].bt)
		      {
		      t2+=cpy2[x].bt;
		      tt[x]=t2;
		      qq++;
		      t2+=oh;
		      ref+=oh;
		      while(cpy[x].at!=J[z].at&&cpy[x].bt!=J[z].bt)
				 { z++; }
		      printf("J%d (%d) | %d   ",z+1,cpy[x].bt,t2-oh);
		      if(t2!=ref)
			{
			printf("OH (%d) | %d   ",oh,t2);

			}
		      }
	       else
		      {
		      t2+=q;
		      cpy2[x].bt-=q;
		      cpy2[x].at=t2;
		      qq++;
		      t2+=oh;
		      ref+=oh;
		      while(cpy[x].at!=J[z].at&&cpy[x].bt!=J[z].bt)
				{ z++; }
		      printf("J%d (%d) | %d   ",z+1,q,t2-oh);
		      printf("OH (%d)|%d   ",oh,t2);
		      }
	    }

	 }


   t++;
   if(t3==t2)
	{t2++;


	}
   };

printf("\nTurnaround Time\n");

for(x=0;x<jbn;x++)
 {z=0;
  while(cpy[x].at!=J[z].at&&cpy[x].bt!=J[z].bt)
	 { z++; }
  printf("tt%d = %d - %d",z+1,tt[x], cpy[x].at);
  tt[x]=tt[x]-cpy[x].at;
  printf(" = %d\n",tt[x]);}

for(x=0;x<jbn;x++)
    {ttave+=tt[x];}

ttave=ttave/jbn;
printf("ttave = %d\n",ttave);
  printf("Waiting Time\n");

for(x=0;x<jbn;x++)
 {z=0;
 while(cpy[x].at!=J[z].at&&cpy[x].bt!=J[z].bt)
	 { z++; }


  printf("wt%d = %d - %d",z+1,tt[x],cpy[x].bt);
  tt[x]=tt[x]-cpy[x].bt;
  printf(" = %d\n",tt[x]);
 }
for(x=0;x<jbn;x++)
    {wtave+=tt[x];}

wtave=wtave/jbn;
printf("wtave = %d\n",wtave);






getch();}//end else

}//end main