You are here

C program to move a car

Program in C using graphics to move a car. A car is made using two rectangles and two circles which act as tires of the car. A for loop is used to move the car forward by changing the rectangle and circle coordinates and erasing the previous contents on screen using clearviewport, you can also use cleardevice. Speed of car can be adjusted using delay function, more the delay lesser will be the speed or lesser the delay your car will move fast. In this program color of the car also keeps on changing, this is accomplished by incrementing the color value by one each time in the for loop, you can also use random function for this purpose. Before you see a car moving you will be asked to press a key.

C programming code

#include <graphics.h>
#include <dos.h>
#include <conio.h>

   int i, j = 0, gd = DETECT, gm;


   outtextxy(25,240,"Press any key to view the moving car");


   for (i = 0; i <= 420; i = i + 10, j++)

      if (i == 420)


   return 0;