注册 登录
编程论坛 C++教室

求助!这个重载函数错在哪里了?

shenyulv 发布于 2009-09-16 00:55, 363 次点击
编写程序的目的是为了让从键盘输入数据,能够找到相应的函数,从而取得最大值。问题就出在第三个和第四个函数上,不知道什么原因,高手帮忙一下哈!

#include "iostream"
using namespace std;
//定义函数
int max11(int,int);
int max11(int,int,int);
double max22(double,double);
double max22(double,double,double);
int main()
{
   
   
    //
    int a,b,c,max1;
    int d,e,f,max2;
   
    cout<<"input two int number:"<<endl;
    cin>>a>>b;
    max1=max11(a,b);
    cout<<"max="<<max1<<endl; //可以正常输出预想的数
   
    cout<<"input three int number:"<<endl;
    cin>>a>>b>>c;
    max1=max11(a,b,c);
    cout<<"max="<<max1<<endl;  //可以正常输出预想的数

   
    cout<<"input two double number:"<<endl;  //从这里开始就有问题了
    cin>>d>>e;
    max2=max22(d,e);
    cout<<"max="<<max2<<endl;
   
    cout<<"input three double number:"<<endl;
    cin>>d>>e>>f;
    max2=max22(d,e,f);
    cout<<"max="<<max2<<endl;
    return 0;
}
  //声明
  int max11(int x,int y)
  {
      int t;
      t=(x>y?x:y);
      return t;
  }

  int max11(int x,int y,int z)
  {
      int t;
      t=(x>y?x:y);
      t=(t>z?t:z);
      return t;
  }

  double max22(double x,double y)
  {
      double t;
      t=(x>y?x:y);
      return t;
  }
double max22(double x,double y,double z)
 {
     double t;
     t=(x>y?x:y);
     t=(t>z?t:z);
     return t;
 }
      


2 回复
#2
serious2009-09-16 05:23
而不是 :
int d,e,f,max2;

你应该用 :
double d,e,f,max2;



#3
shenyulv2009-09-16 12:21
回复 2楼 serious
谢谢了,我太粗心了,呵呵
1