Sunday, August 2, 2009

Why do i get the message 'declaration syntax error' in the following C program?

/* This is just including the header files */











#include%26lt;graphics.h%26gt;





#include%26lt;conio.h%26gt;





#include%26lt;dos.h%26gt;





#include%26lt;math.h%26gt;











/* End of Header Files */























float cosa,cosb,sina,sinb;











/* Till now it was simple you do that in any C++ program. From now onwards starts the CORE */











/* We use the function below for rotation in both horizontal and vertical direction All we have to do is pass the angle in degrees to this function and we will get the corresponding values */











void ini(float cos1,float cos2)





{





cosa=cos(cos1*3.141592736/180);





cosb=cos(cos2*3.141592736/180);





sina=sin(cos1*3.141592736/180);





sinb=sin(cos2*3.141592736/180);





}











/* The function below takes 3 values i.e the values for the 3 Co-ordinates (x,y,z) and returns us the values which we actually plot on the screen i.e it takes the 3-D values and converts them in to a 2-D value which when plotted on the screen seems


3-D */











void plot(int x,int y,int z,int %26amp;x1,int %26amp;y1)





{





x1=x*cosa-y*sina;





y1=x*sina*sinb+y*cosa*sinb+z*cosb;





x1=320+int(x1);





y1=240-int(y1);





}











/* Above we add 320 and 240 respectively to x1 and y1 to shift the co-ordinate system to the centre of the screen */











/* The above 2 functions are what you will only need to create any 3-D object */











void main()





{











/* Here we are initializing the graphics */





gm=CGAC0 (320x200 resolution)





int gd=DETECT,gm;





initgraph(%26amp;gd,%26amp;gm,"c:\\tc"); /* Please enter the path of your bgi directory.In my case it is “c:\\tc\\bgi”.It may be different in your case */











int p=0; /* Variable passed to the ini function above i.e. it contains the angle in degrees*/











while(!kbhit())





{





ini(p,p); /* Here we are calling the ini function which is responsible for the rotation.You can try with different parameters here





ini(p,0) – Horizontal Rotation





ini(0,p) – Vertical Rotation





ini(p,p) – Both Veretical and Horizontal Rotation */











int x[5],y[5]; /*Declaration of array used for storing the converted x,y,z values by the plot function */

















/* Below 4 lines are responsible for plotting the co-ordinates of the base of the Pyramid */











plot(5,5,1,x[0],y[0]);





plot(45,5,1,x[1],y[1]);





plot(5,45,1,x[3],y[3]);





plot(45,45,1,x[4],y[4]);











setcolor(RED); // Sets the color of the lines as RED











/* Below 4 lines are responsible for actually drawing the base of the pyramid from the values x %26amp; y returned by the plot function. Different co-ordinates of the base(4 pts.) are stored in the array declared above*/

















line(x[3],y[3],x[4],y[4]);





line(x[1],y[1],x[4],y[4]);





line(x[0],y[0],x[3],y[3]);





line(x[0],y[0],x[1],y[1]);











/* Below we plot the top of the pyramid and from there using the for loop





join the peak to the 4 co-ordinates of the base hence completing the pyramid*/











plot(20,20,140,x[2],y[2]);











for(int i=0;i%26lt;5;i++)





{





setcolor(BROWN);





line(x[2],y[2],x[i],y[i]);





}











p+=3; /* Incrementing the angle for rotation by 3 degrees.This also alters the speed of rotation try increasing or decreasing this value */











delay(20);





cleardevice(); /* If we don’t use cleardevice here then the pyramid will leave marks all around it’s rotation path. */





}





}










Why do i get the message 'declaration syntax error' in the following C program?
where is the declaration of variable gm ??


No comments:

Post a Comment