我在编写程序时需要帮助,该程序向用户询问他的总薪水,然后再向其提供他的净薪水或净收入。如果工资总额低于204000,则该行业的税率为30%,高于204000的税率为50%。
#include <stdio.h>
int main(void)
{
//Declaring and initializing variabless
double income, tax;
char quit = ' ';
//Loop for multiple oparations
while (quit != 'q' && quit != 'Q') {
//Getting input from the user
printf("\n\n\nInput your annual income:\t");
scanf("%lf", &income);
}
if (income <= 204000) {
tax = (income - 250000) * 30 / 100;
}
else if (income >= 204000) {
tax = (income - 650000) * 50 / 100;
}
//Giving the output
printf("\n\n\nYour tax is:\t%0.2lf Taka\n\n\n", tax);
//Getting out of the loop
getchar();
printf("Input Q or q to exit. Input any other character to continue: ");
scanf("%c", &quit);
}
return 0;
}
答案 0 :(得分:1)
您应该在Google上使用“税项括弧”,以更好地了解如何计算税款。
当您的收入少于或等于204000时,您需要缴纳30%的税:
ngOnInit(){
$.getScript('src/assets_v2/js/main.js');
// do rest of your stuff here.
}
如果没有,则您对前204000项纳税30%,其余部分50%:
tax = income * 30.0 / 100.0;
重要提示:
当您希望计算结果为tax = 204000.0 * 30.0 / 100.0
+ (income - 204000.0) * 50.0 / 100.0;
或double
时,防止使用整数算术通常很重要。例如,如果您写
float
然后,由于30和100都是整数,因此程序将使用整数除法计算30/100,结果为0,而不是0.33333。要强制进行浮点除法,必须确保一个(或两个)操作数是浮点数。
赞:
tax = (30 / 100) * income;
...或这样:
/* 30.0 is a float */
tax = (30.0 / 100) * income;
...甚至是这个
/* 100.0 is a float */
tax = (30 / 100.0) * income;
...或将所有操作数都设置为浮点数或双精度数:
/* income is a double which makes (income * 30) a double */
tax = income * 30 / 100;