Мне просто нужна небольшая помощь в выполнении домашних заданий. Я пишу программу, чтобы найти уравнение перехвата наклона линии. y = mx + b. Проблема в том, что когда b минус, она печатает y = mx + -b вместо y = mx-b. может ли кто-нибудь указать, как это исправить.C++ печать двух знаков
void get2_pt(double *x1, double *y1, double *x2, double *y2)
{
printf("Enter the x-y cordinates of the first point separated by a space =>\n");
scanf("%lf %lf", x1, y1);
printf("Enter the x-y cordinates of the second point separated by a space =>\n");
scanf("%lf %lf", x2, y2);
}
void slope_intcpt_from2_pt(double x1,
double y1,
double x2,
double y2,
double *m,
double *y_intcpt)
{
*m = (y2 - y1)/(x2 - x1);
*y_intcpt = y2 - (*m * x2);
}
void display2_pt(double x1, double y1, double x2, double y2)
{
printf("Two-point form\nm = (%0.2lf-%0.2lf)/(%0.2lf-%0.2lf)\n",
y2,
y1,
x2,
x1);
}
void display_slope_intcpt(double m, double y_intcpt)
{
printf("Entered Q4DSI\n");
printf("Slope-intercept form\ny = %0.2lfx + %0.2lf\n", m, y_intcpt);
}
int main()
{
double x1, x2, y1, y2, m, y_intcpt;
char again;
do
{
get2_pt(&x1, &y1, &x2, &y2);
slope_intcpt_from2_pt(x1, y1, x2, y2, &m, &y_intcpt);
display2_pt(x1, y1, x2, y2);
display_slope_intcpt(m, y_intcpt);
printf("Do another conversion (Y or N) =>\n");
scanf("%c", &again);
} while (again != 'N');
return 0;
}
Распечатайте +, только если b> = 0. Простой if(). – deviantfan