寻找地理和伤害意味着超载

Finding geo and harm mean overloading

本文关键字:意味着 超载 伤害 寻找      更新时间:2023-10-16

我正在为一个类做一个项目,我遇到了一些麻烦,这给了我 2 个错误,我不明白它们是什么意思...... 它给出了错误: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);
}

您的medie函数声明为返回一个float值,但其中没有任何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);
}