|
蓝森林 http://www.lslnet.com 2006年6月6日 10:18
C++编程问题.谢谢!
#include<iostream.h>;
int main()
{ cout<<"Please entre the scores of che,mat,phy."
<<"I will display the average score."<<endl;
double che,mat, phy,ave;
cin>;>;che>;>;mat>;>;phy;
ave=(che+mat+phy)/3;
cout<<"The average="<<ave<<endl;
if(ave>;=90.0)
cout<<"Excenlent!"<<endl;
else
if(ave>;=80.0 && ave<90.0)
cout<<"GOOD!"<<endl;
else
if(ave>;=70.0 && ave<80.0)
cout<<"AVERAGE!"<<endl;
else
if(ave>;=60.0 && ave<70.0)
cout<<"PAST!"<<endl;
else
cout<<"Fail!"<<endl;
return 0;
}//[size=18][color=red]哪里错了,为什么输出结果错误?[/color][/size]
#include<iostream.h>;
int max(int a,int b);
int max(int a,int b,int c);
int main()
{int x,y,z;
cin>;>;x>;>;y>;>;z;
if(z=null)//[size=18][size=24][color=red]错了,但我想在z为空的时候执行函数一.不为空的时候执行函数二
//怎么将z复制定义为空类型?[/color][/size][/size] cout<<max(x,y)<<endl;
else
cout<<max(x,y,z)<<endl;
return 0;
}
int max(int a,int b)
{
return a>;b?a:b;//函数一
}
int max(int a,int b,int c)
{
int t;
t=max(a,b);
return max(t,c);//函数二
}
#include<iostream.h>;
int main()
{
int x,y;
cin>;>;x>;>;y;
cout<<"x="<<x<<endl<<"y="<<y<<endl; //(为什么y的输出值始终是0?)
return 0;
}
#include<iostream.h>;
double Div(double a,double b);
int main()
{
double r;
try{
cout<<"5.2/2.0="<<Div(5.2,2.0)<<endl;
cout<<"5.2/0.0="<<Div(5.2,0.0)<<endl;
cout<<"5.2/5.2=1.0"<<Div(5.2,1.0)<<endl;
}
catch(double d){cout<<"Exception,why->;"<<d<<endl;}
cout<<"All done!"<<endl;
return 0;
}
double Div(double a,double b)
{
if(b==0.0)
throw 1.0E-38;//那个1.0E-38有啥用?
return a/b;
}
[color=red][/color][color=red][/color] |
C++编程问题.谢谢!
你用的是什么环境? |
C++编程问题.谢谢!
能不能把代码格式化一下,这样没人会看的! |
C++编程问题.谢谢!
在引入#include <iostream>;后对cout等流对象的操作前一定要加std的命名空间using namespace std;
或std::cout std::cin,加上试一试 |
C++编程问题.谢谢!
你试试在in main()中,给每个变量说明类型。
还有,你要注意一下编程格式 |
| |