If you simply want to call the IsRectangle()
function, just add the following code between the next:
and }
lines:
if (IsRectangle(x1, y1, x2, y2, x3, y3, x4, y4))
{
printf("The points define a rectangle.\n");
}
else
{
printf("The points do NOT define a rectangle.\n");
}
However, as others have pointed out, there are a few other problems with your code:
- There is no
return
statement in yourmain()
function – it should return anint
as specifed in the declaration. More specifically, it should return zero to indicate that the program ended without problems. - The
goto
statements aren’t doing anything to protect against invalid entries. Theelse
code sections will causeprintf("Invalid Entry\n");
to be triggered, but the code will then continue on to the next section anyway. Also, GOTO statements make Edsger W. Dijkstra sad. - You’ve got almost the exact same code copy-pasted four times, one for each point.
I’d recommend re-factoring your “point input” code into a for
loop, with the x/y values stored in arrays for simplicity:
#include <stdio.h>
int main(int argc, char *argv[])
{
int x[4];
int y[4];
int i;
for (i = 0; i < 4; ++i)
{
printf("Please enter point %d: ", i+1);
while (scanf("%d %d", &x[i], &y[i]) != 2)
{
printf("Invalid point, try again: ");
while (getchar() != '\n') { /* Wait until RETURN is pressed. */ }
}
}
return 0;
}
Alternatively, you could move the input logic into a separate function that is then called four times by main()
to get each point.
solved Using fuctions in C