Car racing in turbo C

niyasc -4 Tallied Votes 10K Views Share

Source code implemented by

Niyas C
S2C
PPMHSS Kottukkara
Kondotty
Malappuram
Kerala St
India

#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<fstream.h>
#include<graphics.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define ENTER 13
class CAR
{
public:
int vel,cp,init,op1,op2,op3,level;
long score;
long lev_score[5];
char player[20];
CAR::CAR()
{
level=1;
vel=1;
cp=300;
init=0;
op1=0;
op2=-20;
op3=-40;
score=0;
lev_score[0]=10000;lev_score[1]=30000;lev_score[2]=60000;lev_score[3]=100000;lev_score[4]=150000;
}
}car;

int randx(void)
{
int x=random(56*8);
if(x<22*8)
{
x=x+(22*8);
}
return(x);
}

void right()
{
if(car.cp<420)
{
car.cp+=10;
}
return;
}
void left()
{
if(car.cp>180)
{
car.cp-=10;
}
return;
}
void score_store()
{
cleardevice();
setcolor(4);
settextstyle(2,0,6);
outtextxy(10,0,"Your score is");
gotoxy(20,2);cout<<car.score;
outtextxy(10,40,"Enter your name to store :");gotoxy(35,4);

gets(car.player);
ofstream score;
score.open("score.dat",ios::app);score<<"\n";
score.write(car.player,20);score<<car.score;
score.close();
}
void disp_score()
{
cleardevice();
setcolor(5);
settextstyle(2,0,9);
outtextxy(200,20,"SCORE BOARD");
ifstream score("score.dat");
char ch; int i=0;gotoxy(1,5);
while(score.get(ch))
{
score.seekg(i,ios::beg);
score.get(ch);
cout<<ch;
i++;
}
getch();
return;
}
void bgmove()
{
if(car.init>5)
{
car.init=1;
}
else
{
car.init+=car.vel;
}

setcolor(RED);
setfillstyle(SOLID_FILL,RED);
sector(car.cp+20,330,0,180,20,30);
setfillstyle(SOLID_FILL,YELLOW);
bar3d(car.cp,333,car.cp+37,360,4,4);
sector(car.cp+20,362,180,360,20,10);

for(int i=car.init;i<70;i+=5)
{
setcolor(GREEN);
setfillstyle(9,GREEN);
bar(16*8,i*8,20*8,(i+2)*8);
bar(60*8,i*8,64*8,(i+2)*8);

}
return;
}
void opp1(int x1)
{
if(car.op1<600)
{
car.op1+=10;
setfillstyle(1,RED);
bar3d(x1,car.op1,x1+30,car.op1+30,2,3);
}
else
{
car.op1=0;
}
return;
}
void opp2(int x2)
{
if(car.op2<600)
{
car.op2+=10;
setfillstyle(1,YELLOW);
bar3d(x2,car.op2,x2+30,car.op2+30,2,3);
}
else
{
car.op2=0;
}
return;
}
void opp3(int x3)
{
if(car.op3<600)
{
car.op3+=10;
setfillstyle(1,BLUE);
bar3d(x3,car.op3,x3+30,car.op3+30,2,3);
}
else
{
car.op3=0;
}
return;
}
int check(int x,int op,int cp)
{
int a[31],b[31],c[40],d[50];
for(int i=0;i<30;i++)
{
a[i]=x+i;
}
for(i=0;i<30;i++)
{
b[i]=op+i;
}
for(i=0;i<40;i++)
{
c[i]=cp+i;
}
for(i=0;i<50;i++)
{
d[i]=300+i;
}
for(i=0;i<40;i++)
{
for(int j=0;j<50;j++)
{
for(int k=0;k<30;k++)
{
if(a[k]==c[i]&&b[k]==d[j])
return 1;
}
}
}
return 0;
}

void logo ()
{
for(int i=1;i<250;i++)
{

setcolor(YELLOW);setfillstyle(SOLID_FILL,YELLOW);
settextstyle(4,HORIZ_DIR,5);
outtextxy(100,100,"DANGEROUS ROAD");
outtextxy(200,140,"RACING");
bar3d(50,200,550,220,10,40);
setcolor(GREEN);
settextstyle(1,HORIZ_DIR,2);
outtextxy(100,400,"LOADING");setfillstyle(SOLID_FILL,GREEN);
bar(190,400,190+i,420);
delay(25);
}
delay(2000);
cleardevice();
return;
}

void loss(void)
{
setcolor(10);
settextstyle(2,0,9);
outtextxy(180,150,"ONE CHANCE LOST");
delay(1000);
return;
}
void over(void)
{
for(int i=1;i<35;i++)
{
cleardevice();delay(20);
settextstyle(1,0,6);setcolor(RED);
outtextxy(150,100,"GAME OVER");
delay(20);

}
delay(2000);cleardevice();
score_store();
getch();
return;
}
void score()
{
car.score=car.score+11*car.vel;
setcolor(5);
settextstyle(2,0,6);
outtextxy(530,12,"Score ");
gotoxy(75,2);
cout<<car.score;
return;
}
void win()
{
cleardevice();
for(int k=0;k<2;k++){
for(int i=0;i<15;i++)
{
setcolor(i);
settextstyle(4,0,5);
outtextxy(200,100,"Congrats!!");
setcolor(i+1);
outtextxy(150,200,"You won the race");
delay(150);
}
}
delay(3000);
score_store();
return;
}
void level(void)
{
int level=car.level;
if(car.score>car.lev_score[level-1])
{
if(car.level<5)
{
car.level++;
if(car.vel<4)
{
car.vel++;}
cleardevice();
settextstyle(2,0,3);
setcolor(4);
outtextxy(4,12,"Level");
gotoxy(5,1);
cout<<car.level;
}
else
{win();}}
settextstyle(2,0,6);
setcolor(5);
outtextxy(4,12,"Level");
gotoxy(8,2);
cout<<car.level;
return;
}
void about()
{
char opt;
while(!kbhit())
{
for(int i=300;i<600;i++)
{
cleardevice();
setcolor(9);
settextstyle(4,0,5);
setfillstyle(9,12);
outtextxy(220,0,"ABOUT");
bar(220,60,370,62);
settextstyle(2,0,5);
setcolor(2);
outtextxy(20,100,"We had completed our work as a part of our computer science project work.");
outtextxy(3,115,"We had tried to reduce maximum problems in our program. Eventhough it may ");
outtextxy(3,130,"consist several technical and logical problems.");
outtextxy(3,165,"WE ARE.........");
outtextxy(3,180,"Wait a moment to enter menu....");
setcolor(6);
settextstyle(2,0,6);
outtextxy(600-i,600-i,"Niyas C");
outtextxy(i-150,215,"Muhammed Dilshad");
outtextxy(i-30,i-130,"Shafeeq ");
outtextxy(600-i,i-150,"Najah Muhammed");
outtextxy(350,600-i,"Azharudheen");
setfillstyle(1,4);
bar3d(180,380,450,460,4,6);
setcolor(1);
settextstyle(2,0,10);
outtextxy(280,380,"S2C");
outtextxy(215,420,"2009-2010");

delay(60);

}
}
getch();
return;
}
int play(void)
{
int life=3,m,x1,x2,x3,s;
re:
while(life)
{
cleardevice();
if(car.op1==0)
{
x1=randx();
car.op1++;
}
else
{
opp1(x1);
}
if(car.op2==0)
{
x2=randx();
car.op2++;
}
else if(car.op2<1)
{car.op2++;}
else
{
opp2(x2);
}
if(car.op3==0)
{
x3=randx();
car.op3++;
}
else if(car.op3<1)
{car.op3++;}
else
{
opp3(x3);
}
setcolor(10);
setfillstyle(0,0);
bar3d(0,0,80,70,4,3);
bgmove();
level();
score();
settextstyle(2,0,6);
setcolor(5);
outtextxy(4,44,"Life");
gotoxy(8,4);cout<<life;
if(check(x2,car.op2,car.cp)||check(x1,car.op1,car.cp)||check(x3,car.op3,car.cp))
{
loss();
life--;

if(life==0)
{
over();
}
car.op1=1;
car.op2=-16;
car.op3=-32;
goto re;
}
if(kbhit())
{
m=getch();
switch(m)
{
case LEFT: left();
	 break;
case RIGHT: right();
	break;
case 'q':exit(0);

}
}
else{
delay(100); }
}

getch();
return(0);
}
void help()
{
cleardevice();
settextstyle(4,0,6);setcolor(13);
outtextxy(200,10,"HELP");textcolor(YELLOW);gotoxy(3,6);
cout<<"\n\n\n\n\n\n\nDPR (Dangerous Road Racing is a simple game in which you have to lead a car by avoiding blocks on road.\nYou have to use the following keys to controll the car\n\n->UP\t--\tForward movement\n->LEFT\t--\tLeftside movement\n->RIGHT\t--\tRightside movement\n->q\t--\tExit from game at any time\n";
getch();
return;
}
void menu()
{
int s=1,t=0,a,p=140;
do
{
do
{
cleardevice();
setcolor(YELLOW);
settextstyle(1,0,4);
outtextxy(230,30,"MENU");
setfillstyle(1,2);
bar(140,80,400,82);
settextstyle(1,0,1);
setcolor(10);
outtextxy(220,137,"PLAY GAME");
outtextxy(220,167,"SCORES");
outtextxy(220,197,"HELP");
outtextxy(220,227,"ABOUT");
outtextxy(220,257,"EXIT");
setcolor(RED);
rectangle(200,p,350,p+20);
a=getch();
switch(a)
{
case UP:if(p>140)
	{p-=30;
	 s--;}
	break;
case DOWN:if(p<260)
	{p+=30;
	s++;};
	break;
case ENTER:a=1;
	break;
default:break;
}
}while(a!=1);
switch(s)
{
case 1:play();
	break;
case 2:disp_score();
	break;
case 3:help();
	break;
case 4:about();
	break;
case 5:exit(0);
default:cprintf("Invalid choice");
	break;
}
}while(t==0);
getch();
}
void main()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"");cleardevice();
logo();
menu();
closegraph();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What a horrible looking mess. Complete and total lack of any programming style.

niyasch 0 Newbie Poster

Niyas, I have aligned the code for you

#include<conio.h> 
#include<process.h> 
#include<stdio.h> 
#include<dos.h> 
#include<stdlib.h> 
#include<fstream.h> 
#include<graphics.h> 
#define LEFT 75 
#define RIGHT 77 
#define UP 72 
#define DOWN 80 
#define ENTER 13 

class CAR 
{ 
    public: 
	int vel, cp, init, op1, op2, op3, level; 
	long score; 
	long lev_score[ 5 ]; 
	char player[ 20 ]; 
	CAR::CAR() 
	{ 
	    level = 1; 
	    vel = 1; 
	    cp = 300; 
	    init = 0; 
	    op1 = 0; 
	    op2 = -20; 
	    op3 = -40; 
	    score = 0; 
	    lev_score[ 0 ] = 10000; 
	    lev_score[ 1 ] = 30000; 
	    lev_score[ 2 ] = 60000; 
	    lev_score[ 3 ] = 100000; 
	    lev_score[ 4 ] = 150000; 
	} 
} 

car; 

int randx( void ) 
{ 
    int x = random( 56 * 8 ); 

    if ( x < 22 * 8 ) 
    { 
	x = x + ( 22 * 8 ); 
    } 

    return ( x ); 
} 

void right() 
{ 
    if ( car.cp < 420 ) 
    { 
	car.cp += 10; 
    } 

    return ; 
} 

void left() 
{ 
    if ( car.cp > 180 ) 
    { 
	car.cp -= 10; 
    } 

    return ; 
} 

void score_store() 
{ 
    cleardevice(); 
    setcolor( 4 ); 
    settextstyle( 2, 0, 6 ); 
    outtextxy( 10, 0, "Your score is" ); 
    gotoxy( 20, 2 ); 
    cout << car.score; 
    outtextxy( 10, 40, "Enter your name to store :" ); 
    gotoxy( 35, 4 ); 
    gets( car.player ); 
    ofstream score; 
    score.open( "score.dat", ios::app ); 
    score << "\n"; 
    score.write( car.player, 20 ); 
    score << car.score; 
    score.close(); 
} 

void disp_score() 
{ 
    cleardevice(); 
    setcolor( 5 ); 
    settextstyle( 2, 0, 9 ); 
    outtextxy( 200, 20, "SCORE BOARD" ); 
    ifstream score( "score.dat" ); 
    char ch; 
    int i = 0; 
    gotoxy( 1, 5 ); 

    while ( score.get( ch ) ) 
    { 
	score.seekg( i, ios::beg ); 
	score.get( ch ); 
	cout << ch; 
	i++; 
    } 

    getch(); 
    return ; 
} 

void bgmove() 
{ 
    if ( car.init > 5 ) 
    { 
	car.init = 1; 
    } 

    else 
    { 
	car.init += car.vel; 
    } 

    setcolor( RED ); 
    setfillstyle( SOLID_FILL, RED ); 
    sector( car.cp + 20, 330, 0, 180, 20, 30 ); 
    setfillstyle( SOLID_FILL, YELLOW ); 
    bar3d( car.cp, 333, car.cp + 37, 360, 4, 4 ); 
    sector( car.cp + 20, 362, 180, 360, 20, 10 ); 

    for ( int i = car.init;i < 70;i += 5 ) 
    { 
	setcolor( GREEN ); 
	setfillstyle( 9, GREEN ); 
	bar( 16 * 8, i * 8, 20 * 8, ( i + 2 ) * 8 ); 
	bar( 60 * 8, i * 8, 64 * 8, ( i + 2 ) * 8 ); 

    } 

    return ; 
} 

void opp1( int x1 ) 
{ 
    if ( car.op1 < 600 ) 
    { 
	car.op1 += 10; 
	setfillstyle( 1, RED ); 
	bar3d( x1, car.op1, x1 + 30, car.op1 + 30, 2, 3 ); 
    } 

    else 
    { 
	car.op1 = 0; 
    } 

    return ; 
} 

void opp2( int x2 ) 
{ 
    if ( car.op2 < 600 ) 
    { 
	car.op2 += 10; 
	setfillstyle( 1, YELLOW ); 
	bar3d( x2, car.op2, x2 + 30, car.op2 + 30, 2, 3 ); 
    } 

    else 
    { 
	car.op2 = 0; 
    } 

    return ; 
} 

void opp3( int x3 ) 
{ 
    if ( car.op3 < 600 ) 
    { 
	car.op3 += 10; 
	setfillstyle( 1, BLUE ); 
	bar3d( x3, car.op3, x3 + 30, car.op3 + 30, 2, 3 ); 
    } 

    else 
    { 
	car.op3 = 0; 
    } 

    return ; 
} 

int check( int x, int op, int cp ) 
{ 
    int a[ 31 ], b[ 31 ], c[ 40 ], d[ 50 ]; 

    for ( int i = 0;i < 30;i++ ) 
    { 
	a[ i ] = x + i; 
    } 

    for ( i = 0;i < 30;i++ ) 
    { 
	b[ i ] = op + i; 
    } 

    for ( i = 0;i < 40;i++ ) 
    { 
	c[ i ] = cp + i; 
    } 
 
    for ( i = 0;i < 50;i++ ) 
    { 
	d[ i ] = 300 + i; 
    } 

    for ( i = 0;i < 40;i++ ) 
    { 
	for ( int j = 0;j < 50;j++ ) 
	{ 
	    for ( int k = 0;k < 30;k++ ) 
	    { 
		if ( a[ k ] == c[ i ] && b[ k ] == d[ j ] ) 
		    return 1; 
	    } 
	} 
    } 

    return 0; 
} 

void logo () 
{ 
    for ( int i = 1;i < 250;i++ ) 
    { 
	int p; 
	setcolor( YELLOW ); 
	setfillstyle( SOLID_FILL, LIGHTBLUE ); 
	settextstyle( 4, HORIZ_DIR, 5 ); 
	outtextxy( 100, 100, "DANGEROUS ROAD" ); 
	outtextxy( 200, 140, "RACING" ); 
	setcolor( 4 ); 
	bar3d( 50, 200, 550, 220, 10, 40 ); 
	setcolor( WHITE ); 
	settextstyle( 2, HORIZ_DIR, 5 ); 
	outtextxy( 290, 380, "LOADING..." ); 
	setfillstyle( SOLID_FILL, GREEN ); 
	bar( 190, 400, 190 + i, 420 ); 
	rectangle( 190, 400, 440, 420 ); 
	delay( 15 ); 
    } 

    delay( 2000 ); 
    cleardevice(); 
    return ; 
} 
 
void loss( void ) 
{ 
    setcolor( 10 ); 
    settextstyle( 2, 0, 9 ); 
    outtextxy( 180, 150, "ONE CHANCE LOST" ); 
    delay( 1000 ); 
    return ; 
} 

void over( void ) 
{ 
    for ( int i = 1;i < 35;i++ ) 
    { 
	cleardevice();delay( 20 ); 
	settextstyle( 1, 0, 6 ); 
	setcolor( RED ); 
	outtextxy( 150, 100, "GAME OVER" ); 
	delay( 20 ); 

    } 

    delay( 2000 ); 
    cleardevice(); 
    score_store(); 
    getch(); 
    return ; 
} 

void score() 
{ 
    car.score = car.score + 11 * car.vel; 
    setcolor( 5 ); 
    settextstyle( 2, 0, 6 ); 
    outtextxy( 530, 12, "Score " ); 
    gotoxy( 75, 2 ); 
    cout << car.score; 
    return ; 
} 

void win() 
{ 
    cleardevice(); 

    for ( int k = 0;k < 2;k++ ) 
    { 
	for ( int i = 0;i < 15;i++ ) 
	{ 
	    setcolor( i ); 
	    settextstyle( 4, 0, 5 ); 
	    outtextxy( 200, 100, "Congrats!!" ); 
	    setcolor( i + 1 ); 
	    outtextxy( 150, 200, "You won the race" ); 
	    delay( 150 ); 
	} 
    } 

    delay( 3000 ); 
    score_store(); 
    return ; 
} 

void level( void ) 
{ 
    int level = car.level; 

    if ( car.score > car.lev_score[ level - 1 ] ) 
    { 
	if ( car.level < 5 ) 
	{ 
	    car.level++; 

	    if ( car.vel < 4 ) 
	    { 
		car.vel++; 
	    } 


	} 

	else 
	{win();} 
    } 

    settextstyle( 2, 0, 6 ); 
    setcolor( 5 ); 
    outtextxy( 4, 12, "Level" ); 
    gotoxy( 8, 2 ); 
    cout << car.level; 
    return ; 
} 

void about() 
{ 
    char opt; 

    while ( !kbhit() ) 
    { 
	for ( int i = 300;kbhit() == 0;i++ ) 
	{ 
	    cleardevice(); 
	    setcolor( 9 ); 
	    settextstyle( 4, 0, 5 ); 
	    setfillstyle( 9, 12 ); 
	    outtextxy( 220, 0, "ABOUT" ); 
	    bar( 220, 60, 370, 62 ); 
	    settextstyle( 2, 0, 5 ); 
	    setcolor( 2 ); 
	    outtextxy( 20, 100, "We had completed our work as a part of our computer science project work." ); 
	    outtextxy( 3, 115, "We had tried to reduce maximum problems in our program. Eventhough it may " ); 
	    outtextxy( 3, 130, "consist several technical and logical problems." ); 
	    outtextxy( 3, 165, "WE ARE........." ); 
	    outtextxy( 3, 180, "Hold a key to enter menu...." ); 
	    setcolor( 6 ); 
	    settextstyle( 2, 0, 6 ); 
	    outtextxy( 600 - i, 600 - i, "Niyas C" ); 
	    outtextxy( i - 150, 215, "Muhammed Dilshad" ); 
	    outtextxy( i - 30, i - 130, "Shafeeq " ); 
	    outtextxy( 600 - i, i - 150, "Najah Muhammed" ); 
	    outtextxy( 350, 600 - i, "Azharudheen" ); 
	    setfillstyle( 1, 4 ); 
	    bar3d( 180, 380, 450, 460, 4, 6 ); 
	    setcolor( 1 ); 
	    settextstyle( 2, 0, 10 ); 
	    outtextxy( 280, 380, "S2C" ); 
	    outtextxy( 215, 420, "2009-2010" ); 

	    delay( 60 ); 

	} 
    } 

    getch(); 
    return ; 
} 

int play( void ) 
{ 
    car.score = 0; 
    int life = 3, m, x1, x2, x3, s; 
re: 

    while ( life ) 
    { 
	cleardevice(); 

	if ( car.op1 == 0 ) 
	{ 
	    x1 = randx(); 
	    car.op1++; 
	} 

	else 
	{ 
	    opp1( x1 ); 
	} 

	if ( car.op2 == 0 ) 
	{ 
	    x2 = randx(); 
	    car.op2++; 
	} 

	else if ( car.op2 < 1 ) 
	{car.op2++;} 

	else 
	{ 
	    opp2( x2 ); 
	} 

	if ( car.op3 == 0 ) 
	{ 
	    x3 = randx(); 
	    car.op3++; 
	} 

	else if ( car.op3 < 1 ) 
	{car.op3++;} 

	else 
	{ 
	    opp3( x3 ); 
	} 

	setcolor( 10 ); 
	setfillstyle( 0, 0 ); 
	bar3d( 0, 0, 80, 70, 4, 3 ); 
	bgmove(); 
	level(); 
	score(); 
	settextstyle( 2, 0, 6 ); 
	setcolor( 5 ); 
	outtextxy( 4, 44, "Life" ); 
	gotoxy( 8, 4 );cout << life; 

	if ( check( x2, car.op2, car.cp ) || check( x1, car.op1, car.cp ) || check( x3, car.op3, car.cp ) ) 
	{ 
	    loss(); 
	    life--; 

	    if ( life == 0 ) 
	    { 
		over(); 
	    } 

	    car.op1 = 1; 
	    car.op2 = -16; 
	    car.op3 = -32; 
	    goto re; 
	} 

	if ( kbhit() ) 
	{ 
	    m = getch(); 

	    switch ( m ) 
	    { 
	    case LEFT: left(); 
		break; 
	    case RIGHT: right(); 
		break; 
	    case 'q': exit( 0 ); 

	    } 
	} 

	else 
	{ 
	    delay( 100 ); 
	} 
    } 

    getch(); 
    return ( 0 ); 
} 

void help() 
{ 
    cleardevice(); 
    settextstyle( 4, 0, 6 ); 
    setcolor( 13 ); 
    outtextxy( 200, 10, "HELP" ); 
    textcolor( YELLOW ); 
    gotoxy( 3, 6 ); 
    cout << "\n\n\n\n\n\n\nDPR (Dangerous Road Racing is a simple game in which you have to lead a car by avoiding blocks on road.\nYou have to use the following keys to controll the car\n\n->UP\t--\tForward movement\n->LEFT\t--\tLeftside movement\n->RIGHT\t--\tRightside movement\n->q\t--\tExit from game at any time\n"; 
    getch(); 
    return ; 
} 

void menu() 
{ 
    int s = 1, t = 0, a, p = 140; 

    do 
    { 
	do 
	{ 
	    cleardevice(); 
	    setcolor( YELLOW ); 
	    settextstyle( 1, 0, 4 ); 
	    outtextxy( 230, 30, "MENU" ); 
	    setfillstyle( 1, 2 ); 
	    bar( 140, 80, 400, 82 ); 
	    settextstyle( 1, 0, 1 ); 
	    setcolor( 10 ); 
	    outtextxy( 220, 137, "PLAY GAME" ); 
	    outtextxy( 220, 167, "SCORES" ); 
	    outtextxy( 220, 197, "HELP" ); 
	    outtextxy( 220, 227, "ABOUT" ); 
	    outtextxy( 220, 257, "EXIT" ); 
	    setcolor( RED ); 
	    rectangle( 200, p, 350, p + 20 ); 
	    a = getch(); 

	    switch ( a ) 
	    { 

	    case UP: if ( p > 140 ) 
		{ 
		    p -= 30; 
		    s--; 
		} 

		break; 

	    case DOWN: if ( p < 260 ) 
		{ 
		    p += 30; 
		    s++; 
		}; 

		break; 

	    case ENTER: a = 1; 

		break; 

	    default: break; 
	    } 
	} 

	while ( a != 1 ); 

	switch ( s ) 
	{ 
	case 1: play(); 
	   	 break; 
	case 2: disp_score(); 
	  	  break; 
	case 3: help(); 
	   	 break; 
	case 4: about(); 
	    	break; 
	case 5: exit( 0 ); 
		 break; 
	} 
    } 

    while ( t == 0 ); 

    getch(); 
} 

void main() 
{ 
    int gdriver = DETECT, gmode, errorcode; 
    initgraph( &gdriver, &gmode, "" ); 
    cleardevice(); 
    logo(); 
    menu(); 
    closegraph(); 
}
NP-complete 42 Junior Poster

Welcome to the 21st century guys...turbo c++ in that sense, is something from the last century which didn't bother to make it to this century (read, didn't bother to update itself). But C++, in all glory has been standardized, i guess, in the last century itself. But Mr. Turbo doesn't even know that!!!

Your code now is indented, but that's not the only "art" in programming. Your code has no single comment.

Here's an open challenge:
can anyone explain the code?? I bet even you (who claims to have written it once upon a time) can't explain.

niyasc -3 Light Poster

Here's an open challenge:
can anyone explain the code?? I bet even you (who claims to have written it once upon a time) can't explain.

Now I'm to busy...
I will explain it on next month on next month. Though could you tell me about problem on the style and code of programme..

NP-complete 42 Junior Poster

>Now i'm too busy...

relax and take some time out to figure out the problem in your code pertaining to "code style".

Read good books and also read about programming style. (just google it up)

And always remember:
"Programming is more about the art of programming"


I may not be the most experienced coder out here, but Ancient Dragon surely is. So if he has labeled your code as "messy" you better take it seriously, unless off course you plan not to code for the industry.

nbaztec 45 Posting Pro in Training

Though could you tell me about problem on the style and code of programme..

I hope you do happen to know that BGI Graphics are deprecated and obsolete. 16-bit DOS compilers shouldn't even be allowed to compile. Don't get it why schools still teach this stuff.

Member Avatar for iamthwee
iamthwee

Don't get it why schools still teach this stuff.

Probably because it allows students to use the included <graphics.h> file without having to add or link any further libraries so they can easily make graphic style programs such as the one above.

Of course, any seasoned programmer, would laugh at turbo c++ because it doesn't follow the standard. In fact you're probably safer writing the code entirely in c.

Schools go with the train of thought that kiddos just need to learn programming basics such as for and while loops with simplistic functions. The semantics as to why it is bad as c++ is generally ignored.

anuragcoder -6 Junior Poster in Training

BGI Graphics are not supported under windows...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

BGI Graphics are not supported under windows...

Since when? Last time I compiled code I wrote 20 years ago, it compiled and worked. And this was within the last year.

Even though BGI and Turbo are old, if you have something to complain about it would be much more helpful if you check your facts first. And keep opinions to yourself. They are not helpful when there's nothing the OP can do about it.

debugger09 0 Light Poster

Turbo c is outdated,but still in our college they use it even to do complex programs

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I can't even get Turbo C to install on 64-bit Windows 7, let alone try to compile anything with it. There will come a day when India's universities will be forced to upgrade their school's compilers and teaching. They are putting their students at a huge disadvantage by teaching with such old tools.

jonsca commented: N/A +4
anuragcoder -6 Junior Poster in Training

Exactly....
Most probably they may upgrade to Visual C++ or
Dev C++ which is free.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My guess is Dev C++, since it's no longer an active project :icon_wink:

Nick Evan commented: :D +12
NP-complete 42 Junior Poster

I don't understand why the condition in India is so pathetic...!! The whole higher education system in India sucks when it comes to Information Technology and Computer Science...my Indian friends...what say?? Shall we start a revolution??

debugger09 0 Light Poster

like wat revolution u want to start

NP-complete 42 Junior Poster

like all students protesting the use of antique softwares may be??

On a serious note...its all about spreading awareness. I have seen many students are simply ignorant about the gotchas of using turbo c or about the cons of writing non-standard code. So on your part you can simply spread the awareness amongst your friends and they in their turn will spread it to others and we can just hope that one day things will change. But for that we really need to appreciate the change. People are too relaxed and it seems that they don't want the change. This attitude needs to change. And change fast.

nbaztec 45 Posting Pro in Training

Lol, tried that. Got labelled as an arrogant freak from people who don't even care about programming! The lame-boy excuse is "It works, doesn't it". If only one day they'd wake up to their PC being toasted by a app they created, just because it returned a value of -5266E-12 to Windows, I'd be a happy man! :)

debugger09 0 Light Poster

no use of doing that
In our college they just teach us commad line programs they will never come across GUI programming.even though we change to any other IDE they just do command line programs

Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster

Let's not get too far of-topic. If you want to discuss the educational system in India be my guest, but please do it in the Geek's lounge.

Shankye 36 Junior Poster

Here is another Turbo-C car racing game ..

http://bit.ly/iefllI

ziyadgodil 0 Newbie Poster

this car race game convert c++ to c

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.