I have been asked to store and draw an array of linesegments. The program should print the message "No intersection" or "Found an intersection" (depending) before terminting if negative coordinates are entered or 2x MAXSEGMENTS segments have been entered.
int main(void) {
lineSeg_t line, allsegments[MAXSEGMENTS];
point_t a, b;
int pointssofar=0, i, v, w, x, y;
OpenGraphics();
while (pointssofar<=(2*MAXSEGMENTS)){
a=GetPoint();
x=XCoord(a);
y=YCoord(a);
if ((x<0)||(y<0))
break;
b=GetPoint();
v=XCoord(b);
w=YCoord(b);
if ((v<0)||(w<0))
break;
line=LineSeg(a, b);
DrawLineSeg(line);
allsegments[((pointssofar+2)/2)]=line;
for (i=0;i<(pointssofar/2);i++){
if (intersect(line, allsegments[i])==TRUE){
printf ("Found an intersection");
pointssofar=2*MAXSEGMENTS;
} else if (pointssofar==(2*MAXSEGMENTS)){
printf("No intersection");
}
}
}
for(i=0;i<(pointssofar/2);i++){
if (intersect(allsegments[pointssofar/2], allsegments[i])==FALSE){
printf("No intersection");
}
}
}
I'm having trouble outputting the messages. Think I'm stuck in the while loop and I'm really not sure how to get out! Thank you in advance.