已解决问题

C++小问题

[ 标签:c++ ]
#include<iostream>
#define MAX(float x, float y)(x>y?x:y)
void main()
{
float a=-2.5,b=-3.2;
cout<<MAX(a,b)<<endl;
}


#include<iostream>
void main()
{
float a=-2.5,b=-3.2;
cout<<(((a)>(b))?(a):(b))<<endl;
}

请改正这两道错误
问题补充  2009-02-28 17:59
能不能把改完的正确答案发来啊
偶不後灬悔 回答:3 人气:6 解决时间:2009-02-28 18:04
  
满意答案
很明显,你这两个程序是比较大小,并输出最大的数
#include<iostream>
#define MAX(float x, float y)(x>y?x:y) //如楼上说的,一般不这样
void main()
{
float a=-2.5,b=-3.2;
cout<<MAX(a,b)<<endl;//cout endl没声明
}

#include<iostream>
void main()
{
float a=-2.5,b=-3.2;
cout<<(((a)>(b))?(a):(b))<<endl; //同样,cout endl没声明,同时括号太多了
}
答案补充
#include<iostream>
float MAX(float x, float y){return x>y?x:y;}
void main()
{
float a=-2.5,b=-3.2;
std::cout<<MAX(a,b)<<std::endl;
}

#include<iostream>
void main()
{
float a=-2.5,b=-3.2;
std::cout<<(((a)>(b))?(a):(b))<<std::endl;//这里括号虽多,但去不去无所谓
}
么么 回答采纳率:45.2% 2009-02-28 18:04
评价答案
  • 是否解决问题(参与评价0次)
  • 0
  • 0
  • 0
  • 是否原创答案(参与评价0次)
  • 0
  • 0

相关内容

其他答案

第一个小括号应该改为大括号而且要在头文件后加using namespace std;
第二个也要先加个 using namespace std;
C++初学者 回答采纳率:10.0% 2009-02-28 02:16
#include<iostream.h>
float MAX(float &x, float &y)//一般情况尽不要使用宏的
{
return x>y?x:y;
}
void main()
{
float a=-2.5,b=-3.2;
cout<<MAX(a,b)<<endl;
}

#include<iostream.h>
void main()
{
float a=-2.5,b=-3.2;
cout<<((a>b)?(a):(b))<<endl;//你这里的括号太多了
}
£ú§ 回答采纳率:33.3% 2009-02-28 09:23