slope_intercept_from2_pt - Takes four input parameters, the x-y coordinates of two points, and returns through output parameters the slope (m) and the y-intercept (b).
intercept_from_pt_slope - Takes three input parameters, the x-y coordinates of one point and the slope, and returns as the function value the y-intercept.
my prof wants me to write these two functions involving these equations and i am not sure how to write them can you help me out with getting started on them:
Two-point form m = (y2 - y1) / (x2 - x1) (x1, y1), (x2, y2)
Point-slope form y - y1 = m(x - x1) m, (x1, y1)
Slope-intercept form y = mx + b m, b
this is what i have so far.....
FUNCTIONS.C
Code:
#include <stdio.h>
#include <stdlib.h>
#define TWOPNT 1
#define PNTSLOPE 2
#define EXIT 3
int get_problem()
{
int option= 1;
do {
/*system ("cls");*/
printf("Select the Mathematical Form you would to convert the slope intercept form\n");
printf("%d. Two-point Form(you know the points on the line).\n", TWOPNT);
printf("%d. Point-slope form (you know the line's slope and one point).\n", PNTSLOPE);
printf("%d. Exit\n", EXIT);
scanf("%d", &option);
} while ((option < TWOPNT) && (option > EXIT));
return option;
}
int get2_pt(int *x1,int *y1, int *x2, int *y2)
{
printf("Please enter the X and Y Coordinates of both points(x1,y1,x2,y2:\n");
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
return (*x1, *y1, *x2, *y2);
}
int get_pt_slope(double *slope, int *x, int *y)
{
printf("Please input the slope and the x and y coordiantes of the point:\n");
scanf("%d%d%d", &slope, &x, &y);
return (*slope, *x, *y);
}
int slope_intercept_from2_pt(int *x1,int *y1, int *x2, int *y2)
{
double slope = 0.0, b = 0.0;
slope = (y2 - y1)/(x2 - x1);
return (slope);
}
MAIN.C
Code:
#include <stdio.h>
#include <stdlib.h>
#define TWOPNT 1
#define PNTSLOPE 2
#define EXIT 3
int main (void)
{
int running = 1;
srand((unsigned int) time(NULL));
while(running)
{
switch(get_problem()) {
case TWOPNT:
/*system("pause");*/
break;
case PNTSLOPE:
break;
case EXIT:
printf("See you next time :)\n");
running = 0;
break;
default:
printf ("That was not an option.....choose again!");
}
}
return 0;
}