🔒 Closed PATULONG SA CODE

Status
Not open for further replies.

pineng

Eternal Poster
Ayan ag problem mga paps:

https://www.Çℎḙḡḡ.com/homework-help...roblem-similar-hanly-koffman-s-proj-q22881929


Ito pa lang nagawa kong code, ewan ko bakit di ma run.

#include <stdio.h>
int get_problem(int choose);
double get2_pt(double, double, double);

int main (){
int choose;
int get_problem();
switch (choose)
{
case 1: get2_pt();
display2_pt();
display_slope_intcpt(); break;
case 2: get_pt_slope();
display_pt_slope();
display_slope_intcpt();break;
}
char response;
printf("\nDo another conversion (Y or N)=> ");
scanf(" %c", &response);
switch(response)
{
case 'Y': get_problem();
case 'N': return 0;
}
}




int get_problem(int choose){
int choose;printf("%s\n%s\n%s\n%s","Select the form that you would like to convert to slope-intercept form: ",
"1)Two-point form (you know the points in the line)",
"2)Point-slope form(you know the line's slope and one point)", "=> ");scanf("%d", &choose);return choose;
}
//functions
double get2_pt(double *a, double*b, double *c, double *d)
{ double x1,x2,y1,y2;
printf("Enter the x-y coordinates of the first point separated by a space=>");
scanf("%lf%lf", &x1,&y1);
printf("Enter the x-y coordinates of the second point separated by a space => ");
scanf("%lf%lf", &x2,&y2);
}
double get_pt_slope(double *a, double*b, double *c)
{ double m,x1,y1;
printf("Enter the slope => ");
scanf("%lf", &m);
printf("Enter the x-y coordinates separated by a space=>");
scanf("%lf%lf", &x1,&y1);
}
double slope_intcpt_from2_pt()
{
//get x1, x2, y1, y2
//returns slope (m )and y intercept or (b)
}
double intcpt_from_pt_slope()
{
//get x1, y1, m
//returns y intercept or b.
}
double display2_pt()
{
//get x1, x2, y1, y2
//display two point form line equation
}
double display_pt_slope()
{
//get x1, y1, m
//display point slope equation with a heading
}
double display_slope_intcpt()
{
//get m and y intercept
//display slope intercept

}
 
di ko pa rin magets ko ano ito paps haha
assignment.png

Eto sample code na may function prototypes:
Code:
#include <stdio.h>
#include <stdlib.h>

int get_operation();
double two_pointForm();
double point_slope();
char do_continue();

int main(void) {
    char answer = ' ';
    while (answer != 'N' && answer != 'n') {
        int myoperation = get_operation();
        switch(myoperation) {
            case 1:
                printf("The slope is: %.2lf\n", two_pointForm());
                break;
            case 2:
                printf("Point's slope: %.2lf\n", point_slope());
                printf("\nYOU HAVE TO DO THIS PART!\n");
        }
        answer = do_continue();
    }
    printf("\nThank you for using this program!");
    printf("\n---------------------------------\n\n");
    return 0;
}

int get_operation() {
        size_t nbyte=1;
        int op=0;
        char *my_string = malloc(nbyte+1);
        puts(" ");
    while (op != 1 && op != 2 && op != 3) {
        printf("Mathematical Models\n");
        printf("-------------------\n");
                printf("1) Two-point form (you know two points on the line)\n");
                printf("2) Point's slope (you know the line's slope and one point\n");
                printf("3) Exit\n");
                printf("Enter your choice: ");
                getline(&my_string, &nbyte, stdin);
                sscanf(my_string, "%d", &op);
                if (op != 1 && op != 2 && op != 3) {
                        printf("\nINVALID INPUT. Please re-enter.\n");
                }
    }
        free(my_string);
        return op;
}

double two_pointForm() {
    double slope, x1, y1, x2, y2;
    size_t nbytes=10;
    char *my_string = malloc(nbytes+1);
    printf("\nTwo-point Form\n===============\n");
    printf("FORMULA:\n");
    printf("\t\ty2 - y2\n");
    printf("\t m = ----------------\n");
    printf("\t\tx1 - x1\n");
    printf("\n\tWhere: m = slope\n\n");
    printf("Enter the X-Y coordinates of the first point separated by space: ");
    getline(&my_string, &nbytes, stdin);  
    sscanf(my_string, "%lf %lf", &x1, &y1);
    printf("Enter the X-Y coordinates of the second point separated by space: ");
    getline(&my_string, &nbytes, stdin);  
    sscanf(my_string, "%lf %lf", &x2, &y2);
    slope = (y2-y1)/(x2-x1);
    free(my_string);
    return slope;
}

double point_slope() {
    printf("\nPoint Slope\n===============\n");
    printf("FORMULA:\n");
}

char do_continue() {
        size_t nbyte=1;
        char answer=' ';
        char *my_string = malloc(nbyte+1);
        puts(" ");
    while (answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n') {
                printf("Do you want to do another computation <y/n>: ");
                getline(&my_string, &nbyte, stdin);
                sscanf(my_string, "%s", &answer);
                if (answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n') {
                        printf("\nINVALID INPUT.\n");
                }
        }
        free(my_string);
        return answer;
}
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 10
    Replies
  • 527
    Views
  • 3
    Participants
Last reply from:
pineng

Trending Topics

Online now

Members online
1,058
Guests online
958
Total visitors
2,016

Forum statistics

Threads
2,274,923
Posts
28,959,366
Members
1,233,485
Latest member
senpaikatzu_88
Back
Top