I have a problem when I'm doing my debugging: Xcode gives:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
I think it's a problem with my dynamic array...
My assignment is to calculate the perimeter of a polygon with points.
So, my program receives points (x and y) to fill an array of Points, then I made another array, distance, which I fill with all the distances, and then I can calculate the perimeter.
I don't know if it's very clear but I'm a beginner in C++.
#include <iostream>
#include "Point.h"
#include "Polygone.h"
using namespace std;
int main() {
int numberSide;
int x,y;
Point* array = nullptr;
Polygone myPolygone;
cout<<"enter number of sides:"<<endl;
cin>>numberSide;
float* distance=new float[numberSide];
cout<<"enter points:"<<endl;
for (int i=0; i<numberSide; i++) {
cin>>x>>y;
Point p(x,y);
array[i]=p;
}
for (int i=0; i<numberSide-1; i++) {
distance[i]=array[i].distance(array[i+1]);
}
distance[numberSide]=array[0].distance(array[numberSide]);
myPolygone.perimeter(distance);
delete [] distance;
return 0;
}