请教:计算圆面积的积序错在哪里?

tcysky 2004-05-08 03:07:41
#include<iostream.h>
float resu(float x)//声明自定义函数

main()
{
float n=3.1415926;
float f,r,z;
cin>>r;
resu(r);//调用自定议函数
z=n*r*r;//计算圆的面积
cout<<z;//输出结果
}

float resu(float x)
{
if(x>0)
retrun x;
else
cout<<"sorry,the number is wrong.";
}
...全文
62 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcysky 2004-05-08
  • 打赏
  • 举报
回复
//////为什么显示worning :unreachable code?
#include<iostream.h>
float resu(float x);

main()
{
float n=3.1415926;
float f,r,z;
cin>>r;
resu(r);
z=n*r*r;
cout<<z;
}

float resu(float x)
{
if(x>0)
return x;
else
{
return 0;
cout<<"sorry,the number is wrong.";//为什么显示worning :unreachable code?
}
}
wil 2004-05-08
  • 打赏
  • 举报
回复
标准才鸟好仔细
saoyu 2004-05-08
  • 打赏
  • 举报
回复
else分支加上返回值,然后在main判断返回值做相应的出错处理
#include<iostream.h>
float resu(float x);

main()
{
float n=3.1415926;
float f,r,z;
cin>>r;
if(resu(r)==0)
printf("error");
else{
z=n*r*r;//计算圆的面积
cout<<z;//输出结果
}
}

float resu(float x)
{
if(x>0)
retrun x;
else
return 0;
}
liushuaiboy 2004-05-08
  • 打赏
  • 举报
回复
#include<iostream.h>
float resu(float x);//此处少了分号
main()//最好加上void
{
float n=3.1415926;
float r,z;//f 定义却没有使用
cin>>r;
resu(r);//调用自定议函数
z=n*r*r;//计算圆的面积
cout<<z;//输出结果
}

float resu(float x)
{
if(x>0)
return x;//最大意的地方return写错了,^_^
else
{
cout<<"sorry,the number is wrong.";
return 0.0;//最好加上返回值
}
}
lzf20lzf 2004-05-08
  • 打赏
  • 举报
回复
float resu(float x)
{
if(x>0)
retrun x;
else
cout<<"sorry,the number is wrong.";*****************有问题吧
}
yiminggw 2004-05-08
  • 打赏
  • 举报
回复
没有return
hangdian 2004-05-08
  • 打赏
  • 举报
回复
#include<iostream.h>
float resu(float x);//声明自定义函数

int main()
{
double n=3.1415926;
float r,z;
cin>>r;
resu(r);//调用自定议函数
z=(float)n*r*r;//计算圆的面积
cout<<z;//输出结果
return 0;
}

float resu(float x)
{
if(x>0)
return x;
else
{
cout<<"sorry,the number is wrong!";
return 0;
}
}

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧