Hai, I'm a higher secondary student in kerala. As our project I have to create a simple car racing program in c++. I implemented the following code fragment. May I get some instructions to improve it?
Especially the method of accessing input to controll movement of object?
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
void car(int &);
void right(int &);
void left(int &);
void bgmove(int);
void play(void);
void car(int &cp)
{ gotoxy(cp,25);
cout<<"|--|";
gotoxy(cp-1,26);
cout<<"| |";
gotoxy(cp,27);
cout<<"++++";
return;
}
void right(int &cp)
{ if(cp<40)
{
cp=cp+1;
}
return;
}
void left(int &cp)
{ if(cp>20)
{
cp=cp-1;
}
return;
}
void bgmove(int i)
{ for(int l=i;l<50;l+=5)
{
gotoxy(15,l);cout<<"***";gotoxy(45,l);cout<<"***";
}
return;
}
void main()
{
clrscr();
int cp=28,n,s=1;
char m;
cout<<"Enter number of laps\n";
cin>>n;
clrscr();
for(int i=0;i<n;i++)
{ for(int j=1;j<5;j+=s)
{ clrscr();
bgmove(j);
car(cp);
move:
m=getch();
delay(20);
switch(m)
{
case '4':left(cp);
break;
case '6':right(cp);
break;
case '8':break;
case 'q':exit(0);
case 'c':if(s<5)
{s=s+1;}
default :goto move;
}
}
}
}