Its showing size of type is unknown or zero

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<iostream.h>
#include<math.h>
int gc,gd=DETECT;
int x[3][4],tx,ty,i=0;
float turn[3][4];


			    void draw()
			{       moveto(x[0][0],x[1][0]);
				for(i=1;i<4;i++)
				{
					lineto(x[0][i],x[1][i]);
					x[2][i]=1;

				}
					lineto(x[0][0],x[1][0]);
			}

void rot()
{double ang;
float rot[3][3];
cout<<"enter the angle through which u want to rotate the figure\n";
cin>>ang;
rot[2][2]=1;
rot[2][1]=rot[2][0]=rot[1][2]=rot[0][2]=0;
rot[0][0]=rot[1][1]=cos(ang);
rot[0][1]=-sin(ang);
rot[1][0]=sin(ang);
}



void rotate()
{
for(int k=0;k<3;k++)
{for(int j=0;j<4;j++)
  {for(int i=0;i<3;i++)
    {
      turn[k][j]=turn[k][j]+((rot[j][i]) * (x[i][j]));
    }
  }
 }
}

void copy()
{
for(i=0;i<4;i++)
{x[0][i]=turn[0][i];
 x[1][i]=turn[1][0];
}
}

void main()

{clrscr;
initgraph(&gc,&gd,"");
cout<<"Enter the four cordinates of rectangle \n";
for(i=0;i<4;i++)
{
scanf("%d%d",&x[0][i],&x[1][i]);
}

draw();
rot();
rotate();
copy();
draw();
getch();

}

Please mail me at <EMAIL SNIPPED>

Dani AI

Generated

Brief, practical checklist (building on comments from , and ) to get a 2D rotation program working and eliminate the mysterious compiler/runtime errors.

First, isolate scope and initialization problems. Make the 3x3 rotation matrix available to the function that multiplies it with the point matrix (return it, pass it as a parameter, or make it file-scoped). Do not rely on uninitialized accumulators — compute each output element into a local sum and assign it (do not accumulate into garbage). Convert any input angle to radians before calling sin/cos (these expect radians) — see [std::cos] (https://en.cppreference.com/w/cpp/numeric/math/cos).

Second, verify the matrix-multiplication indexing. For a 3x3 rotation matrix applied to a 3xN point matrix, the correct element computation is: output[row][col] = sum_over_k rot[row][k] * point[k][col]. A concise pseudocode:

for r = 0..2:
  for c = 0..N-1:
    sum = 0.0
    for k = 0..2:
      sum += rot[r][k] * pts[k][c]
    out[r][c] = sum

Ensure loops only access valid indices for each array dimension.

Third, fix the copy-back and drawing steps. When copying transformed coordinates back, use the same column index for both rows. Test the math first by printing numeric coordinates before attempting any old-style graphics API — many modern compilers no longer ship the legacy graphics library used in the original code. If you need visuals, consider a current library (SFML or SDL) rather than platform-specific BGI headers.

Debugging tips: compile with a high warning level (for example g++ -Wall -Wextra), print intermediate matrices (rotation matrix, original points, transformed points), and post exact compiler error text and line numbers if problems persist. For the rotation math, see the standard rotation-matrix reference: [Rotation matrix] (https://en.wikipedia.org/wiki/Rotation_matrix).

Recommended Answers

All 3 Replies

I'd be much more willing to look for the problem if you listed the line number the compiler complained about. Generally giving us all of the information you have about the problem is a good idea.

remember sin and cos takes angle in radians. But other than that
I don't know whats your problem?

Several problems are apparent.
(a) Turn is not initialized so will definitely be wrong
(b) loop variable j run 0 to 3 inclusive (j<4). so you access undefined memory locations in rot.
(c) rot is local only to the function rotate so the whole function is pointless. [make it global if you want it to work like that]
(d) clrscr; is incorrect, you must have it as clrscr(); if it doesn't take any parameters.
(e) I am sure you have function copy wrong, you use [0][1] rather than [0].

That will do to start.

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.