[英]IF statement that is greater than and less than specific numbers
I have a project where I have to create a tax application. 我有一个必须创建税务申请的项目。 I have two integers: gross and taxrate.
我有两个整数:总额和税率。 When the user inputs his gross income, I want it to multiply the certain percentage of the tax rate in his bracket for the tax due.
当用户输入他的总收入时,我希望它乘以其括号内税率的一定百分比作为应付税款。 My code is the following:
我的代码如下:
if (gross < 9075) {
taxrate = (int) (gross * .10);
}
else (gross > 9075 && < 36900) {
taxrate = (int) (gross * .15);
}
It tells me there is an error, so I assume I am messing up somewhere. 它告诉我有一个错误,所以我认为我在某个地方搞砸了。 Is there a way to create a proper if statement that goes between two numbers?
有没有办法创建介于两个数字之间的适当if语句?
You must explicitly state both operands to any binary operator, including comparison operators. 您必须将两个操作数明确声明为任何二进制运算符,包括比较运算符。 Try
尝试
} else if (gross > 9075 && gross < 36900) {
Incidentally you may need to consider the case of exactly 9075
, either with 顺便说一句,您可能需要考虑正好是
9075
的情况,或者
if (gross <= 9075){
OR 要么
} else if (gross >= 9075 && < 36900) {
It looks like you are using a conditional with the else statement, and not using your operators correctly. 看起来您正在使用条件语句和else语句,而不是正确使用运算符。 You want to change this to
您要将其更改为
else if (gross > 9075 && gross < 36900)
Notice I have changed else
to else if
and changed the conditional to have the comparisons done correctly. 注意,我将
else
更改为else if
并更改了条件以正确完成比较。
Try giving it as 尝试给它作为
taxrate = (int) (gross*0.10f);
and 和
taxrate = (int) (gross*0.15f);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.