C++ 发现地质和危害意味着超载

C++ 发现地质和危害意味着超载,c++,C++,我正在为一个班级做一个项目,我遇到了一些麻烦,这给了我两个错误,我不明白它们的意思。。。 它给出了一个错误:c4716“medie”必须返回一个值 代码如下: #include <iostream> #include <stdlib.h> #include<math.h> using namespace std; float medie(float a, float b, float c) { float MG,MA; MG= sqrt(a*

我正在为一个班级做一个项目,我遇到了一些麻烦,这给了我两个错误,我不明白它们的意思。。。 它给出了一个错误:c4716“medie”必须返回一个值

代码如下:

#include <iostream>
#include <stdlib.h>
#include<math.h>
using namespace std;

float medie(float a, float b, float c)
{
    float MG,MA;
    MG= sqrt(a*b*c);
    cout<< "MG="<< MG<<endl;
    MA=(2*a*b*c)/(a+b+c);
    cout<< "MA="<< MA<<endl;

}

float medie(float a,float b,float c,float d)
{
    float MG,MA;
    MG= sqrt(a*b*c*d);
    cout<< "MG="<< MG<<endl;
    MA=(2*a*b*c*d)/(a+b+c+d);
    cout<< "MA="<< MA<<endl;
}

int main()
{
    float a,b,c,d;
    cout<<"a="<<endl;
    cin>>a;
    cout<<"b="<<endl;
    cin>>b;
    cout<<"c="<<endl;
    cin>>c;
    cout<<"d="<<endl;
    cin>>d;

    medie(a,b,c);

    medie(a,b,c,d);
}
#包括
#包括
#包括
使用名称空间std;
浮动介质(浮动a、浮动b、浮动c)
{
MG,MA;
MG=sqrt(a*b*c);

cout您的
medie
函数被声明为返回一个
float
值,但其中没有任何
return
语句。如果您将它们声明为return
void
错误应该消失

#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;

void medie(float a, float b, float c)
{
    float MG,MA;
    MG = sqrt(a*b*c);
    cout<< "MG="<< MG<<endl;
    MA = (2*a*b*c)/(a+b+c);
    cout<< "MA="<< MA<<endl;

}

void medie(float a,float b,float c,float d)
{
    float MG,MA;
    MG = sqrt(a*b*c*d);
    cout<< "MG="<< MG<<endl;
    MA = (2*a*b*c*d)/(a+b+c+d);
    cout<< "MA="<< MA<<endl;
}

int main()
{
    float a,b,c,d;
    cout<<"a="<<endl;
    cin>>a;
    cout<<"b="<<endl;
    cin>>b;
    cout<<"c="<<endl;
    cin>>c;
    cout<<"d="<<endl;
    cin>>d;

    medie(a,b,c);

    medie(a,b,c,d);
}
#包括
#包括
#包括
使用名称空间std;
无效介质(浮子a、浮子b、浮子c)
{
MG,MA;
MG=sqrt(a*b*c);

cout
medie
被定义为返回float,但它没有这样做。那么我必须做什么呢?你可以声明函数
void
,而不是
float
是的thx以获取建议,但现在我遇到了另一个问题,程序只使用第二个函数。这很奇怪。你确定只更改了两个函数的返回值吗我测试了我在答案中发布的代码,它运行得很好。