//challenge,, fix this!
#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, oh, jbn, x, y, z, t, ref=0, tt[80];
again:
clrscr();
textcolor(YELLOW);
gotoxy(20,5); cprintf("*** ROUND ROBIN WITH OVERHEAD ALGORITHM ***");
textcolor(10);
gotoxy(5,7); cprintf("How many jobs do you want to enter?(max 15 jobs) ");
scanf("%d", &jbn);
if(jbn>15)
{
printf("\tThe maximum jobs that can be entered is 15. Please try again.\n");
printf("\tPress enter");
getch();
goto again;}
else
{
gotoxy(10,9); printf("Please fill out the following 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 the quantum time:\t");
scanf("%d",&q);
y=y+2;
gotoxy(10,y); printf("Please enter the overhead time:\t");
scanf("%d",&oh);
y=y+2;
gotoxy(10,y);
puts("All the datas are inputted. Please 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");
for(x=0;x<jbn;x++)
ref=ref+cpy[x].bt;
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++)
{printf("|");
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("|\n");
printf("Turnaround Time\n");
for(x=0;x<jbn;x++)
{printf("tt = %d - %d",tt[x]+cpy[0].at, cpy[x].at);
tt[x]=tt[x]-cpy[x].at+cpy[0].at;
printf(" = %d\n",tt[x]);}
printf("Waiting Time\n");
for(x=0;x<jbn;x++)
{printf("wt = %d - %d",tt[x],cpy[x].bt);
tt[x]=tt[x]-cpy[x].bt;
printf(" = %d\n",tt[x]);}
printf("%dcpy.at %dJ.at %dcpy2.at ",cpy[1].at,J[1].at,cpy2[1].at);
printf("%dcpy.bat %dJ.bat %dcpy2.bat ",cpy[2].bt,J[1].bt,cpy2[1].bt);
getch();}//end else
}//end main