【问题标题】:intelliSense: no instance of overloaded function "sqrt" matches the argument list argument types are: (double *)intelliSense:没有重载函数“sqrt”的实例与参数列表参数类型匹配:(double *)
【发布时间】:2014-11-12 16:51:12
【问题描述】:

这段代码有什么问题??!!!我正在制作一个程序试图解决二次方程并看到这个错误并且无法解决它我应该改为浮动还是什么??

#include<stdio.h>
#include<conio.h>
#include<math.h>

void solve_quadratic(double a,double b,double c ,double *d ,double *r1,double *r2);
int main (void)
{
double x,y,z;
double root1,root2;
double desc;
printf("Enter the value of a:  ");
scanf("%lf",&x);
printf("Enter the value of b :  ");
scanf("%lf",&y);
printf("Enter the value of c :   ");
scanf("%lf",&z);

solve_quadratic(x,y,z,&desc,&root1,&root2);
if (desc<0)
{
    printf("No Result !!!");
}
else if (desc>0)
{
    printf("The value of the first root = %f \n",root1);
    printf("The value of the second root = %f  \n",root2);
}
getch();
return 0;

}

void solve_quadratic(double a,double b,double c ,double *d ,double *r1,double *r2)
{
*d=b*b-4*a*c;
if (d>=0)
{
    *r1=(-b+sqrt(d))/(2*a);
    *r2=(-b-sqrt(d))/(2*a);
}
}

【问题讨论】:

    标签: c++ math.h


    【解决方案1】:
    *r1=(-b+sqrt(d))/(2*a);     <<<< d is pointer not double.
    

    您正在将指向 double 的指针传递给 sqrt。应该是:-

    *r1=(-b+sqrt(*d))/(2*a);
    

    【讨论】:

    • @TadrosEbrahim:答案正是告诉你该做什么。使用*ddouble 本身,而不是d,一个指向它的指针。
    猜你喜欢
    • 1970-01-01
    • 2019-07-16
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多