Question: #include #include #include struct Point { int x, y; };struct Point setPoints(struct Point p) { int temp, status; printf(Please enter x coordinate: ); status =
#include
while(status!=1 || p.x<0) { while((temp=getchar()) != EOF && temp != ' '); printf("Invalid input... please enter a positive number: "); status = scanf("%d", &p.x); } printf("Please enter y coordinate: "); status = scanf("%d", &p.y); while(status!=1 || p.y<0) { while((temp=getchar()) != EOF && temp != ' '); printf("Invalid input... please enter a positive number: "); status = scanf("%d", &p.y); } return p; } //returns the distance between two points double getDistance(struct Point a, struct Point b) { double distance; distance = sqrt((a.x - b.x) * (a.x - b.x) + (a.y-b.y) *(a.y-b.y)); return distance; } double comparePoints(struct Point a, struct Point b) { double points; if (struct Point b == struct Point a) printf ("The two lines are not equal"); else printf ("the two lines are equal"); } int main() { struct Point a, b; int choice=0; int c=0; while(1) { printf("1. Enter coordinates of line "); printf("2. Compare the two lines "); printf("3. Quit "); printf("Please enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: { printf("Enter coordinates of first point "); a = setPoints(a); printf("Enter coordinates of second point "); b = setPoints(b); printf("Distance between a and b: %lf ", getDistance(a, b)); break; } case 2: { c = comparePoints(c); break; } case 3: { break; } } } return 0; }
Trying to figure out how i can pass the struct to another function to compare the two lines by length. The assignment entails using structs for the user to input the x and y values of two lines then comparing them by total length. I can get the two lines by length but am unable to pass the struct to compare it in another function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
