一元“*”的类型参数无效(有整数?
我读过其他类似的问题,但似乎没有一个有效...... 我的代码是:
int flowRateFormula(int pipeDiameter,double velocity)
{
int integer3;
integer3=PI*(1/4)*(pow(pipeDiameter,2))*velocity;
return integer3;
}
错误是:
flowRate.c: In function ‘flowRateFormula’:
flowRate.c:38:13: error: invalid type argument of unary ‘*’ (have ‘int’)
怎么办? 顺便说一句 PI 已定义
I have read other questions like this but none seemed to work...
My code is:
int flowRateFormula(int pipeDiameter,double velocity)
{
int integer3;
integer3=PI*(1/4)*(pow(pipeDiameter,2))*velocity;
return integer3;
}
And the error is:
flowRate.c: In function ‘flowRateFormula’:
flowRate.c:38:13: error: invalid type argument of unary ‘*’ (have ‘int’)
What to do?
BTW PI IS DEFINED
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很可能您在某处有该行
,这会导致您的代码相当于:
并且无法编译。将其替换为 例如
请注意,
(1/4)
将被计算为 0,因为整数除法返回一个整数。您可能想使用1.0/4.0
。Most likely you have the line
somewhere, which causes your code to be equivalent to:
and this fails to compile. Replace it with e.g.
Note also that
(1/4)
will be evaluated to 0, because integer division returns an integer. you probably want to use1.0/4.0
.您需要首先声明 PI 的值。
You need to declare a value for PI first.
PI有定义吗?我敢打赌它是空的。顺便说一句,(1/4) 会给你零,使你的整个表达式为零。
Is PI defined? I'm betting it's empty. BTW, (1/4) will give you zero, making your whole expression zero.