Thread: Help with program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    5

    Help with program

    This program is for converting from point slope form or two point form into slope intercept form based off of what the user wants. It also needs to prompt the user if they want to run it again. But it doesn't work passed prompting for which form they want to convert from.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    
    void get_problem(int *input);
    void get2_pt(double *x_1,double *y_1, double *x_2, double *y_2);
    void get_pt_slope(double *slope_pt_slope, double *y, double *x);
    void slope_intcpt_from2_pt(double x_1, double y_1, double x_2, double y_2, double *slope, double *intcpt);
    void intcpt_from_pt_slope(double x, double y, double slope_pt_slope, double *intcpt, double *slope);
    void display2_pt(double x_1,double y_1, double x_2, double y_2);
    void display_pt_slope(double slope, double x, double y);
    void display_slope_intcpt(double slope, double intcpt);
    int main(void)
    {
        char letter;
         int input;
        double x_1,y_1,x_2,y_2;
        double slope_pt_slope,x,y;
        double slope,intcpt;
    
        do{
        get_problem(&input);
        switch(input){
        case '1':
    
        get2_pt(&x_1,&y_1,&x_2,&y_2);
        slope_intcpt_from2_pt(x_1,y_1,x_2,y_2,&slope,&intcpt);
        display2_pt(x_1,y_1,x_2,y_2);
        display_slope_intcpt(slope,intcpt);
            break;
    
        case '2':
        get_pt_slope(&slope_pt_slope,&y,&x);
        intcpt_from_pt_slope(x,y,slope_pt_slope,&intcpt,&slope);
        display_pt_slope(slope,x,y);
        display_slope_intcpt(slope,intcpt);
            break;
        }
        printf("Do another conversion (Y or N) =>");
        scanf("%c",&letter);
        }while(letter == 'Y' || letter == 'y');
    }
    void get_problem(int *input){
        printf("                                                                       \n");
        printf("Select the form that you would like to convert to slope-intercept form:\n");
        printf("                                                                       \n");
        printf("1) Two-point form (you know two points on the line)\n");
        printf("                                                                       \n");
        printf("2) Point-slope form(you know the lines slope and first point)\n");
        scanf("%d",&*input);
    }
    
    void get2_pt(double *x_1,double *y_1, double *x_2, double *y_2){
    printf("Enter the x-y coordinates of the point separated by a space");
    scanf("%lf %lf",&*x_1,&*y_1);
    printf("Enter the x-y coordinates of the point separated by a space ");
    scanf("%lf %lf",&*x_2,&*y_2);
    }
    void get_pt_slope(double *slope_pt_slope, double *y, double *x){
        printf("Enter the slope");
        scanf("%lf",&*slope_pt_slope);
        printf("Enter the x-y coordinates of the point separated by a space ");
        scanf("%lf %lf",&*x,&*y);
    }
    void slope_intcpt_from2_pt(double x_1, double y_1, double x_2, double y_2, double *slope, double *intcpt){
    
        *slope = (y_2 - y_1) / (x_2 - x_1);
        *intcpt = ((*slope * (-x_1) + y_1));
    }
    void intcpt_from_pt_slope(double x, double y, double slope_pt_slope, double *intcpt, double *slope){
      *intcpt = (slope_pt_slope * (-x) + (-y));
      *slope = slope_pt_slope;
    }
    void display2_pt(double x_1,double y_1, double x_2, double y_2){
    printf("Two-Point Form");
    printf("(%f - %f) / (%f - %f)",y_2,y_1,x_2,x_1);
    }
    void display_pt_slope(double slope, double x, double y){
    printf("Point-Slope Form\n");
    printf("y - %f = %f(x - %f",y,slope,x);
    }
    
    void display_slope_intcpt(double slope, double intcpt){
    printf("Slope-Intercept Form\n");
    printf("y = %f x + %f ",slope,intcpt);
    }
    Attached Files Attached Files
    Last edited by Salem; 03-23-2017 at 11:52 AM. Reason: Inlined code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  2. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  3. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM

Tags for this Thread