could the C pundits on the message board plz tell me how to improve my telephone network simulation program.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
extern int busy=0,s1=-1,s2=-1,s3=-1,d1=-1,d2=-1,d3=-1,t1=0,t2=0,t3=0;
void main()
{
int link=0,block=0,success=0;
void gens1(),gend1(),gent1(),gens2(),gend2(),gent2(),ge ns3(),gend3(),gent3(),tim(),wind(),print();
wind();
randomize();
do
{
delay(100);
tim();
if(link==3 && random(100)%9==0)
block++;
print();
gotoxy(56,17);
printf("%d",s1+1);
gotoxy(63,17);
printf("%d",d1+1);
gotoxy(70,17);
printf("%02d",t1);
gotoxy(56,19);
printf("%d",s2+1);
gotoxy(63,19);
printf("%d",d2+1);
gotoxy(70,19);
printf("%02d",t2);
gotoxy(56,21);
printf("%d",s3+1);
gotoxy(63,21);
printf("%d",d3+1);
gotoxy(70,21);
printf("%02d",t3);
gotoxy(72,29);
printf("%d",(success+block+busy));
gotoxy(72,31);
printf("%d",success);
gotoxy(72,33);
printf("%d",block);
gotoxy(72,35);
printf("%d",busy);
gotoxy(72,45);
printf("%d",link);
if(link==0)
{
gens1();
gend1();
gent1();
++link;
++success;
continue;
}
if(link==1)
{
gens2();
gend2();
gent2();
++link;
++success;
continue;
}
if(link==2)
{
gens3();
gend3();
gent3();
++link;
++success;
continue;
}
--t1;
--t2;
--t3;
if(t1<=0)
{
gotoxy(56,17);
printf(" ");
gotoxy(63,17);
printf(" ");
gotoxy(70,17);
printf(" ");
}
if(t2<=0)
{
gotoxy(56,19);
printf(" ");
gotoxy(63,19);
printf(" ");
gotoxy(70,19);
printf(" ");
}
if(t3<=0)
{
gotoxy(56,21);
printf(" ");
gotoxy(63,21);
printf(" ");
gotoxy(70,21);
printf(" ");
}
if(t1<=0 && (t2>=0 || t3>=0))
{
--link;
s1=s2;
d1=d2;
t1=t2;
s2=s3;
d2=d3;
t2=t3;
s3=-1;
d3=-1;
t3=0;
}
if(t2==0 && (t1>=0 || t3>=0))
{
--link;
s2=s3;
d2=d3;
t2=t3;
s3=-1;
d3=-1;
t3=0;
}
if(t3<=0)
{
--link;
}
} while(!kbhit());
}
void print()
{
textcolor(RED);
gotoxy(11,29);
cprintf("%d",s1+1);
gotoxy(11,35);
cprintf("%d",s2+1);
gotoxy(11,41);
cprintf("%d",s3+1);
gotoxy(41,29);
cprintf("%d",d1+1);
gotoxy(41,35);
cprintf("%d",d2+1);
gotoxy(41,41);
cprintf("%d",d3+1);
textcolor(s1+1);
gotoxy(10,30);
cprintf("%c%c%c",219,219,219);
textcolor(s2+1);
gotoxy(10,36);
cprintf("%c%c%c",219,219,219);
textcolor(s3+1);
gotoxy(10,42);
cprintf("%c%c%c",219,219,219);
textcolor(d1+1);
gotoxy(40,30);
cprintf("%c%c%c",219,219,219);
textcolor(d2+1);
gotoxy(40,36);
cprintf("%c%c%c",219,219,219);
textcolor(d3+1);
gotoxy(40,42);
cprintf("%c%c%c",219,219,219);
}
void gens1()
{
randomize();
s1=random(8);
}
void gend1()
{
do
{
d1=random(8);
}while(s1==d1);
}
void gent1()
{
t1=0;
t1=random(30)+1;
}
void gens2()
{
do
{
s2=random(8);
} while(s2==s1 || s2==d1);
}
void gend2()
{
do
{
d2=random(8);
if(d2==d1 || d2==s1)
busy++;
} while(d2==s2 || d2==d1 || d2==s1);
}
void gent2()
{
t2=0;
t2=random(30)+1;
}
void gens3()
{
do
{
s3=random(8);
} while(s3==s1 || s3==s2 || s3==d1 || s3==d2);
}
void gend3()
{
do
{
d3=random(8);
if(d3==s1 || d3==s2 || d3==d1 || d3==d2)
busy++;
} while(d3==s3 || d3==s1 || d3==s2 || d3==d1 || d3==d2);
}
void gent3()
{
t3=0;
t3=random(30)+1;
}
void tim()
{
struct time t;
gettime(&t);
gotoxy(39,7);
printf("%02d:%02d:%02d",t.ti_hour, t.ti_min, t.ti_sec);
}
void wind()
{
int x,y=0;
clrscr();
textcolor(YELLOW);
for(x=1;x<=79;x++)
{
gotoxy(x,1);
cprintf("%c",205);
gotoxy(x,10);
cprintf("%c",205);
gotoxy(x,50);
cprintf("%c",205);
}
for(x=1;x<=49;x++)
{
gotoxy(x,20);
cprintf("%c",205);
}
for(x=2;x<=49;x++)
{
gotoxy(1,x);
cprintf("%c",186);
gotoxy(79,x);
cprintf("%c",186);
}
for(x=11;x<=49;x++)
{
gotoxy(50,x);
cprintf("%c",186);
}
gotoxy(1,1);
cprintf("%c",201);
gotoxy(79,1);
cprintf("%c",187);
gotoxy(1,50);
cprintf("%c",200);
gotoxy(79,50);
cprintf("%c",188);
gotoxy(1,10);
cprintf("%c",204);
gotoxy(79,10);
cprintf("%c",185);
gotoxy(50,10);
cprintf("%c",203);
gotoxy(50,50);
cprintf("%c",202);
// End of window system//
textcolor(RED);
gotoxy(25,3);
cprintf("SIMULATION OF TELEPHONE SYSTEM");
gotoxy(24,5);
cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
gotoxy(32,7);
textcolor(BLUE);
cprintf("CLOCK :");
// End of heading//
gotoxy(22,12);
textcolor(MAGENTA);
cprintf("TELEPHONES");
gotoxy(22,13);
cprintf("----------");
for(x=1;x<=8;x++)
{
textcolor(x);
gotoxy(y+3,15);
cprintf("%c%c%c",219,219,219);
textcolor(RED);
gotoxy(y+4,17);
cprintf("%d",x);
y=y+6;
}
//End of telephones//
textcolor(MAGENTA);
gotoxy(17,22);
cprintf("TELEPHONE SWITCHING");
gotoxy(17,23);
cprintf("-------------------");
y=0;
for(x=1;x<=3;x++)
{
gotoxy(14,30+y);
printf("%c-----------------------%c",174,175);
gotoxy(23,29+y);
textcolor(GREEN);
cprintf("LINK %d",x);
y=y+6;
}
//End of telephone switching//
textcolor(MAGENTA);
gotoxy(52,12);
cprintf("LIST OF CALLS IN PROGRESS");
gotoxy(52,13);
cprintf("-------------------------");
gotoxy(55,15);
textcolor(BLUE);
cprintf("FROM TO DURATION");
textcolor(YELLOW);
for(x=0;x<=21;x++)
{
gotoxy(x+54,16);
cprintf("%c",196);
gotoxy(x+54,18);
cprintf("%c",196);
gotoxy(x+54,20);
cprintf("%c",196);
gotoxy(x+54,22);
cprintf("%c",196);
}
for(x=0;x<=4;x++)
{
gotoxy(53,x+17);
cprintf("%c",179);
gotoxy(60,x+17);
cprintf("%c",179);
gotoxy(66,x+17);
cprintf("%c",179);
gotoxy(76,x+17);
cprintf("%c",179);
}
//end of progress calls//
textcolor(MAGENTA);
gotoxy(60,26);
cprintf("COUNTERS");
gotoxy(60,27);
cprintf("--------");
gotoxy(53,29);
printf("Processed Calls : ");
gotoxy(53,31);
printf("Successful Calls : ");
gotoxy(53,33);
printf("Blocked Calls : ");
gotoxy(53,35);
printf("Busy Calls : ");
gotoxy(62,40);
textcolor(MAGENTA);
cprintf("LINKS");
gotoxy(62,41);
cprintf("-----");
gotoxy(53,43);
printf("Maximum Links : 3");
gotoxy(53,45);
printf("Links in Use : ");
}