By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

I made a program but when i compile it, it says error to many types in declaration

P: 1
I made a program but when I compile it, it says error to many types in declaration.

Expand|Select|Wrap|Line Numbers
  1. #include<graphics.h>
  2. #include<iostream.h>
  3. #include<conio.h>
  4. #include<process.h>
  5. #include<dos.h>
  6. #include<math.h>
  7. #include<stdlib.h>
  8.  
  9.  
  10.  
  11. int BirdSpeed=0;
  12. int BirdColor=0;
  13. int AngleProjection=0;
  14. int Velocity=0;
  15. int Power=0;
  16. int Lives=0;
  17. int Level=1;
  18. int Pigs=0;
  19. int TotalPigs=0;
  20. int PigCx[5];
  21. int PigCy[5];
  22. int PigSz[5];
  23.  
  24.  
  25. void Blast();
  26. void PlayGame();
  27. void BirdMenu();
  28. void GameInput();
  29. void Scene();
  30. void MenuChoice();
  31. void MakeMenu();
  32. void Pig(int,int,int);
  33. void Instructions();
  34. void EndScreen();
  35.  
  36. void EndScreen(int x)
  37. { switch(x)
  38.   {
  39.    case 1:
  40.     cleardevice();
  41.   settextstyle(TRIPLEX_FONT,0,8);
  42.   setcolor(RED);
  43.   outtextxy(240,30," RIP ");
  44.   setcolor(WHITE);
  45.   settextstyle(DEFAULT_FONT,0,1);
  46.   outtextxy(240,200,"\n You Died \n");
  47.   outtextxy(240,240,"\n Level:             \n");
  48.   outtextxy(240,280,"\n Pigs Killed:       \n");
  49.   char level[10];
  50.   char killedpigs[10];
  51.   int killed=TotalPigs-Pigs;
  52.   itoa(killed,killedpigs,10);
  53.   itoa(Level,level,10);
  54.   outtextxy(310,240,level);
  55.   outtextxy(360,280,killedpigs);
  56.   setcolor(GREEN);
  57.   outtextxy(240,300,"Restart?(Y/N)");
  58.   char ch=getch();
  59.   if(ch=='y')
  60.     BirdMenu();
  61.  
  62.   else
  63.     exit(0);
  64.   break;
  65.  
  66.   case 2:
  67.     cleardevice();
  68.   settextstyle(TRIPLEX_FONT,0,8);
  69.   setcolor(RED);
  70.   outtextxy(240,30," Congrats ");
  71.   setcolor(WHITE);
  72.   settextstyle(DEFAULT_FONT,0,1);
  73.   outtextxy(240,200,"\n You Won!!!! \n");
  74.   outtextxy(240,240,"\n Level:             \n");
  75.   outtextxy(240,280,"\n Pigs Killed:       \n");
  76.   char level2[10];
  77.   char killedpigs2[10];
  78.   int killed2=TotalPigs-Pigs;
  79.   itoa(killed2,killedpigs2,10);
  80.   itoa(Level,level2,10);
  81.   outtextxy(310,240,level2);
  82.   outtextxy(360,280,killedpigs2);
  83.   setcolor(GREEN);
  84.   outtextxy(240,300,"Restart?(Y/N)");
  85.   char ch1=getch();
  86.   if(ch1=='y')
  87.     BirdMenu();
  88.  
  89.   else
  90.     exit(0);
  91.   break;
  92.    }
  93.  }
  94. void Blast(int x, int y,int r)
  95. {
  96.    float i;
  97.    for(i=0;i<=r;i=i+1)
  98.    {
  99.  
  100.     setcolor(14);
  101.     circle(x,y,i);
  102.     sound(i*100);
  103.     delay(1);
  104.     setcolor(0);
  105.     circle(x,y,i);
  106.     nosound();
  107.    }
  108.    }
  109.  
  110.    void Collision(int birdcx,int birdcy)
  111.     {
  112.     for(int i=1;i<=TotalPigs;i++)
  113.     {
  114.        if(PigSz[i]==0)
  115.         continue;
  116.  
  117.        if((birdcx>=(PigCx[i]-PigSz[i]-9)&&birdcx<=(PigCx[i]+PigSz[i]))&&((birdcy>=(PigCy[i]-PigSz[i])-9)&&(birdcy<=(PigCy[i]+PigSz[i]+9))))
  118.         {
  119.         Blast(PigCx[i],PigCy[i],PigSz[i]);
  120.         PigSz[i]=0;
  121.         Pigs--;
  122.         }
  123.     }
  124.  
  125.     }
  126.  
  127.  void Level_1_Scene()
  128.  { Lives=2;
  129.    Pigs=TotalPigs=1;
  130.    PigCx[1]=200;PigCy[1]=300;PigSz[1]=10;
  131.    Pig(200,300,10);
  132.  }
  133.  void Level_2_Scene()
  134.  { Lives=3;
  135.    Pigs=TotalPigs=2;
  136.    PigCx[1]=580;PigCy[1]=400;PigSz[1]=10;
  137.    PigCx[2]=540;PigCy[2]=400;PigSz[2]=15;
  138.    int pigs=Pigs;
  139.    while(pigs>0)
  140.    { Pig(PigCx[pigs],PigCy[pigs],PigSz[pigs]);
  141.      pigs--;   }
  142.    }
  143.  void Level_3_Scene()
  144.  { Lives=4;
  145.  Pigs=TotalPigs=4;
  146.  PigCx[1]=580;PigCy[1]=400;PigSz[1]=10;
  147.  PigCx[2]=600;PigCy[2]=400;PigSz[2]=10;
  148.  PigCx[3]=620;PigCy[3]=400;PigSz[3]=10;
  149.  PigCx[4]=600;PigCy[4]=350;PigSz[4]=20;
  150.  int pigs=Pigs;
  151.    while(pigs>0)
  152.    { Pig(PigCx[pigs],PigCy[pigs],PigSz[pigs]);
  153.      pigs--;   }
  154.  }
  155.  void Pig(int cx,int cy,int sz)
  156.  {
  157.   setcolor(GREEN);
  158.   circle(cx,cy,sz);
  159.   circle(cx,cy+3,sz/3);
  160.   setcolor(WHITE);
  161.   circle(cx+3,cy-3,2);
  162.   circle(cx-3,cy-3,2);
  163.  
  164.  }
  165.  void Bird(int cx,int cy)
  166. {
  167.  setlinestyle(0,0,3);
  168.  setcolor(BirdColor);
  169.  circle(cx,cy,10);
  170.  setcolor(WHITE);
  171.  line(cx-8,cy-8,cx-1,cy-1);
  172.  line(cx+8,cy-8,cx+1,cy-1);
  173.  setcolor(YELLOW);
  174.  line(cx-8,cy+3,cx+8,cy+3);
  175.  /*
  176.  line(cx,cy,cx+6,cy+3);
  177.  line(cx+6,cy+3,cx,cy+3);
  178.  line(cx,cy,cx,cy+6);
  179.    */
  180. }
  181.  void ClrBird(int cx,int cy)
  182. {
  183.  setlinestyle(0,0,3);
  184.  setcolor(BLACK);
  185.  circle(cx,cy,10);
  186.  line(cx-8,cy-8,cx-1,cy-1);
  187.  line(cx+8,cy-8,cx+1,cy-1);
  188.  line(cx-8,cy+3,cx+8,cy+3);
  189. }
  190.  
  191. void MenuChoice()
  192. { char choice;
  193.  choice=getch();
  194.  sound(500);
  195.  delay(100);
  196.  nosound();
  197.  switch(choice)
  198.  
  199.  {
  200.   case 's':
  201.   BirdMenu();
  202.   break;
  203.  
  204.  
  205.   case 'e':
  206.   exit(0);
  207.   break;
  208.  
  209.   default:
  210.   EndScreen(1);
  211.   }
  212. }
  213. void MakeMenu()
  214. {
  215.   cleardevice();
  216.   settextstyle(DEFAULT_FONT,0,6);
  217.   outtextxy(60,110,"ANGRY BIRDS");
  218.   settextstyle(DEFAULT_FONT,0,1);
  219.   setcolor(BLUE+BLINK);
  220.   outtextxy(100,200,"(S)START");
  221.   setcolor(RED+BLINK);
  222.   outtextxy(100,280,"(E)EXIT");
  223.  
  224.   do
  225.   {int n;
  226.   n=0;
  227.   while( n<30)
  228.  {if(kbhit()!=0)
  229.     goto endanim;
  230.  BirdColor=(n%10)+1;
  231.   Bird(400,300+(5*n));
  232.  BirdColor=(n%10)+2;
  233.   Bird(430,300+(5*n));
  234.  BirdColor=(n%10)+3;
  235.   Bird(450,300+(5*n));
  236.   ClrBird(400,300+(5*n));
  237.   ClrBird(430,300+(5*n));
  238.   ClrBird(450,300+(5*n));
  239.   n++;
  240.   }
  241.    while( n>=30)
  242.  {
  243.   if( kbhit()!=0)
  244.    goto endanim;
  245.  BirdColor=(n%10)+1;
  246.   Bird(400,(5*n)+300);
  247.  BirdColor=(n%10)+2;
  248.   Bird(430,(5*n)+300);
  249.  BirdColor=(n%10)+3;
  250.   Bird(450,(5*n)+300);
  251.   ClrBird(400,(5*n)+300);
  252.   ClrBird(430,(5*n)+300);
  253.   ClrBird(450,(5*n)+300);
  254.   n--;
  255.   }
  256.  
  257.   } while(1);
  258.   endanim:
  259.   MenuChoice();
  260. }
  261. void BirdMenu()
  262. {
  263.   cleardevice();
  264.   settextstyle(DEFAULT_FONT,0,4);
  265.   setcolor(CYAN);
  266.   outtextxy(20,20,"Choose a bird");
  267.   settextstyle(SMALL_FONT,0,7);
  268.   setcolor(RED);
  269.   outtextxy(40,60,"(R)RED");
  270.   outtextxy(50,80,"Speed:*** \n Luck:***** \n Special Move:DROP");
  271.   setcolor(YELLOW);
  272.   outtextxy(40,120,"(Y)YELLOW");
  273.   outtextxy(50,140,"Speed:***** \n Luck:*** \n Special Move:BOOST");
  274.   setcolor(BLUE);
  275.   outtextxy(40,180,"(B)BLUE");
  276.   outtextxy(50,200,"Speed:**** \n Luck:**** \n Special Move:BOMB");
  277.   setcolor(WHITE);
  278.   outtextxy(40,250,"(E)Exit");
  279.  
  280. char inp=getch();
  281.  
  282.  sound(900);
  283.  delay(100);
  284.  nosound();
  285.  
  286.   if(inp=='r')
  287.     { BirdSpeed=3;BirdColor=4;}
  288.   if(inp=='y')
  289.     { BirdSpeed=4;BirdColor=14;}
  290.   if(inp=='b')
  291.     { BirdSpeed=4;BirdColor=1;}
  292.   else if(inp=='e')
  293.     { MakeMenu(); }
  294.     Instructions();
  295. }
  296.  
  297.  
  298.  
  299. void Instructions()
  300. {
  301. cleardevice();
  302.   settextstyle(TRIPLEX_FONT,0,3);
  303.   setcolor(RED);
  304.   outtextxy(20,20,"Instructions");
  305.   setcolor(YELLOW);
  306.   settextstyle(DEFAULT_FONT,0,1);
  307.   outtextxy(20,70,"Press W to increase the power");
  308.   outtextxy(20,90,"Press S to decrease the power");
  309.   outtextxy(20,110,"Press A to increase the angle");
  310.   outtextxy(20,130,"Press D to decrease the angle");
  311.   setcolor(GREEN);
  312.   outtextxy(20,170,"Press Spacebar to launch");
  313.   outtextxy(20,190,"Press N for special move");
  314.   setcolor(WHITE);
  315.   outtextxy(20,230,"Press any key to continue");
  316.   getch();
  317.   sound(800);
  318.   delay(100);
  319.   nosound();
  320.   Scene();
  321. }
  322. void Scene()
  323. {
  324.     cleardevice();
  325.     setcolor(GREEN);
  326.     line(0,420,650,420);
  327.     setlinestyle(SOLID_LINE,1,THICK_WIDTH);
  328.     setfillstyle(HATCH_FILL,RED);
  329.     floodfill(10,455,GREEN);
  330.     setcolor(BROWN);
  331.     line(75,420,75,380);
  332.     line(85,420,85,380);
  333.     line(75,380,65,370);
  334.     line(85,380,95,370);
  335.     setcolor(RED);
  336.     line(65,370,70,370);
  337.     line(85,370,95,370);
  338.     Level_1_Scene();
  339.    {
  340.       while(Lives>=0 && Pigs>0)
  341.        { GameInput(); Lives--;}
  342.  
  343.    if(Lives>=0)
  344.    { Level++;
  345.      Level_2_Scene();
  346.       while(Lives>=0 && Pigs>0)
  347.     { GameInput(); Lives--;}
  348.  
  349.  
  350.      if(Lives>=0)
  351.     {Level++;
  352.      Level_3_Scene();
  353.        while(Lives>=0 && Pigs>0)
  354.     { GameInput(); Lives--;}
  355.     if(Lives>=0)
  356.      EndScreen(2);
  357.      }
  358.      else
  359.       EndScreen(1);
  360.     }
  361.     else
  362.      EndScreen(1);
  363.   }
  364.   }
  365.     void GuideLine(int power,int angle,int color)
  366.     {
  367.     float a_rad=angle*(3.14156/180);
  368.     setcolor(color);
  369.     setlinestyle(DOTTED_LINE,0,3);
  370.     line(80,370,80+(power*cos(a_rad)),370+(power*sin(a_rad)));
  371.     }
  372.     void ClrGuideLine(int power,int angle)
  373.     {
  374.  
  375.     float a_rad=angle*(3.14156/180);
  376.     setcolor(BLACK);
  377.        setlinestyle(DOTTED_LINE,0,3);
  378.        line(80,370,80+(power*cos(a_rad)),370+(power*sin(a_rad)));
  379.     }
  380.  
  381.  void GameInput()
  382.     {  setfillstyle(SOLID_FILL,BLACK);
  383.        bar(0,0,200,100);
  384.       int color=0;
  385.     AngleProjection=360;
  386.     Power=20;
  387.     GuideLine(20,360,2);
  388.     Bird(80,370);
  389.     char ch;
  390.     setfillstyle(SOLID_FILL,RED);
  391.     outtextxy(50,20,"Lives :");
  392.     bar(120,20,Lives*10+120,25);
  393.     setfillstyle(SOLID_FILL,BLUE);
  394.     outtextxy(50,50,"Pigs Left  :");
  395.     bar(150,50,Pigs*10+150,55);
  396.     setfillstyle(SOLID_FILL,YELLOW);
  397.     outtextxy(50,80,"Level :");
  398.     bar(120,80,Level*10+120,85);
  399.  
  400.     while((ch=getch())!=' ')
  401.     {
  402.        ClrGuideLine(Power,AngleProjection);
  403.         if(ch==97&&AngleProjection>270)
  404.         AngleProjection-=5;
  405.  
  406.          if(ch==100&&AngleProjection<360)
  407.            AngleProjection+=5;
  408.  
  409.         if(ch==119&&Power<30)
  410.            Power+=5;
  411.  
  412.         if(ch==115&&Power>5)
  413.         Power-=5;
  414.      if(Power<=15)
  415.           color=2;
  416.      else if(Power>15&&Power<=20)
  417.           color=14;
  418.      else if(Power>20)
  419.           color=4;
  420.  
  421.      GuideLine(Power,AngleProjection,color);
  422.      Bird(80,370);
  423.     }
  424.  
  425.     ClrGuideLine(Power,AngleProjection);
  426.     PlayGame();
  427.  
  428.     }
  429. void PlayGame()
  430. {
  431.   float t,a_rad;
  432.   int x=80,y=370;
  433.   int oldx,oldy;
  434.     a_rad=(360-AngleProjection)*3.141592/180;
  435.  
  436.     for(t=0;y<=420 &&x<=640 && x>=0;t+=0.02)
  437.     {
  438.     oldx=x;
  439.     oldy=y;
  440.  
  441.     x+=(Power*BirdSpeed*0.25*cos(a_rad)*t);
  442.     y-=((Power*0.8*sin(a_rad)*t)-(15*t*t));
  443.  
  444.     if(kbhit()!=0)
  445.         { char ch;
  446.         ch=getch();
  447.         if(ch=='n')
  448.         {if(BirdColor==RED)
  449.         Power=0;
  450.          if(BirdColor==YELLOW)
  451.         Power+=30;
  452.          if(BirdColor==BLUE)
  453.         {int Rand;
  454.          Rand=rand()%10;
  455.          if(Rand%2==0)
  456.            BirdColor=RED;
  457.          else
  458.            BirdColor=YELLOW; }
  459.         }
  460.         }
  461.     Collision(x,y);
  462.     ClrBird(oldx,oldy);
  463.     Bird(x,y);
  464.  
  465.  
  466.      }
  467.    getch();
  468.    ClrBird(x,y);
  469.  
  470. }
  471.  
  472. void main()
  473. {
  474.     int driver,mode;
  475.     driver=DETECT;
  476.     initgraph(&driver,&mode,"C:\\turboC3\\bgi\\");
  477.  
  478.     MakeMenu();
  479.  
  480.     closegraph();
  481. }
Jun 12 '17 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,396
Which statement is associated with the line number that accompanies the error message?

My first guess is that one of your variable names is inadvertently the same as that of a typedef in one of the header files you're including.

It would help a lot if you enclosed your source code in CODE tags. That would preserve the formatting and, most importantly, provide line numbers that we could reference.

What compiler are you using?
The versions of C that I'm most familiar will complain if variable declarations are anywhere other than the first statements in a curly-brace block. For example, the declaration of level after the call to outtextxy() in function EndScreen().

You should convert the function declarations at the start of the file into function prototypes by specifying the argument types. For example, change "void Blast();" to "void Blast(int x, int y, int r);"
Jun 16 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.