Homework Help!

topic posted Tue, March 16, 2004 - 1:20 PM by  Zack
Share/Save/Bookmark
Advertisement
Alright, i told y'all you'd be helpin me soon

heres my first problem:
Why is this function telling me that i'm not using an array?
i passed it an array with the x and y floats but i keep geting the error, or should they not be floats?

float segmentLength(float, float, float, float);
float polygonPerimeter (float x, float y, int pnts)
{
float d;
int i;
for (i=0; i<pnts; i++);

d = segmentLength (x[i], x[i+1], y[i], y[i+1]);

return 0;
posted by:
Zack
Kansas
Advertisement
Advertisement
  • Re: Homework Help!

    Tue, March 16, 2004 - 3:46 PM
    IT's telling you x and y are not arrays because you have declared them as floats. They should be *(float* x, float* y, int pts)
    It doesn't matter what you call it with if you declare it improperly.
    • Re: Homework Help!

      Tue, March 16, 2004 - 3:47 PM
      Without the star in front of the parenthesis. I think tribe did that. That's what I get for not previewing.
  • Re: Homework Help!

    Tue, March 16, 2004 - 10:40 PM
    but when i do that it just gives me a different error, i think it was "array or pointer type" error. so does that mean the problem is back in the 'main' funtion?

    also, i guess i should have said the purpose of this funtion is to give the perimeter of a polygon. not that that changes the situation.
    • Re: Homework Help!

      Wed, March 17, 2004 - 7:13 AM
      This compiles fine, at least on its own (notice that I got rid of the semicolon at the end of the for also, this was an empty for followed by one single segmentLength execution). If there is any other problem it is in the caller of polygonPerimiter or within segmentLength. Try to follow all the other changes and figure out why I did them. Each one is important.

      float segmentLength(float, float, float, float);
      float polygonPerimeter (float *x, float *y, int pnts)
      {
      float d=0.0;
      int i;
      for (i=0; i<pnts; i++)
      d += segmentLength (x[i], x[i+1], y[i], y[i+1]);

      return d;
      }