C:我无法让这个示例税务计划发挥作用

时间:2015-03-05 02:21:28

标签: c

该计划应该已经支付了您的收入和税款,并确定您欠或欠的款项。它不起作用。

它给我的一些警告是括号变量被赋值从未使用过的值,条件总是为真/假。我不知道我错过了什么。

#include<stdio.h>

void main() {
    int income, paid;
    float tax, owed;
    float bracket1, bracket2, bracket3, bracket4, bracket5, bracket6;

    printf("Enter taxable income: ");
    scanf("%d", &income);
    printf("Enter tax paid during the year: ");
    scanf("%d", &paid);

    // Determines amount paid in each tax bracket
    bracket1 = (17,850 - 0) * 0.10;
    bracket2 = (72,500 - 17,851) * 0.15 - 893;
    bracket3 = (146,400 - 72,501) * 0.25 - 8143;
    bracket4 = (223,050 - 146,401) * 0.28 - 12,535;
    bracket5 = (398,350 - 223,051) * 0.33 - 23,688;
    bracket6 = (450,000 - 398,351) * 0.35 - 31,655;

    // Determines total tax owed
    if (income > 0 && income <= 17,850)
        tax = income * 0.10;
    else if (income > 17,850 && income <= 72,500)
        tax = bracket1 + (income - 17,850) * 0.15 - 893;
    else if (income > 72,500 && income <= 146,400)
        tax = bracket1 + bracket2 + (income - 72,500) * 0.25 - 8143;
    else if (income > 146,400 && income <= 223,050)
        tax = bracket1 + bracket2 + bracket3 + (income - 146,400) * 0.28 - 12,535;
    else if (income > 223,050 && income <= 398,350)
        tax = bracket1 + bracket2 + bracket3 + bracket4 + (income - 223,050) * 0.33 - 23,688;
    else if (income > 398,350 && income <= 450,000)
        tax = bracket1 + bracket2 + bracket3 + bracket4 + bracket5 + (income - 398,350) * 0.35 - 31,655;
    else if (income > 450,000)
        tax = bracket1 + bracket2 + bracket3 + bracket4 + bracket5 + bracket6 + (income - 450,000) * 0.396 - 52,355;
    else

    owed = tax - paid;

    if (owed > 0)
        printf("Tax due is %.02f", owed);   
    else if (owed < 0)
        printf("Refund is %.02f", owed); }

是的,至于我得到的错误。

Line 17: Code has no effect in function main
Line 18: Code has no effect in function main
Line 19: Code has no effect in function main
Line 22: Condition is always true in function main
Line 24: Condition is always true in function main
Line 26: Condition is always true in function main
Line 28: Condition is always true in function main
Line 29: Code has no effect in function main
Line 30: Condition is always true in function main
Line 31: Code has no effect in function main
Line 32: Condition is always false in function main
Line 33: Code has no effect in function main
Line 33: Unreachable code in function main
Line 34: Condition is always false in function main
Line 35: Unreachable code in function main
Line 35: Code has no effect in function main
Line 35: 'tax' is assigned a value that is never used in function main
Line 43: Function should return a value in function main
Line 14-19: 'bracket 1-6' is assigned a value that is never used in function main

1 个答案:

答案 0 :(得分:-1)

  1. 不要将化妆品中的整数和浮点数合并到圆形结果中。
  2. 使用“。”数字“,”不是为了那个。
  3. 另外一个不允许计算欠款。
  4. 修正:

    #include<stdio.h>
    
    void main() {
        float income, paid;
        float tax, owed;
        float bracket1, bracket2, bracket3, bracket4, bracket5, bracket6;
    
        printf("Enter taxable income: ");
        scanf("%f", &income);
        printf("Enter tax paid during the year: ");
        scanf("%f", &paid);
    
        // Determines amount paid in each tax bracket
        bracket1 = (17.850 - 0) * 0.10;
        bracket2 = (72.500 - 17.851) * 0.15 - 893;
        bracket3 = (146.400 - 72.501) * 0.25 - 8143;
        bracket4 = (223.050 - 146.401) * 0.28 - 12.535;
        bracket5 = (398.350 - 223.051) * 0.33 - 23.688;
        bracket6 = (450.000 - 398.351) * 0.35 - 31.655;
    
        // Determines total tax owed
        if (income > 0 && income <= 17.850)
            tax = income * 0.10;
        else if (income > 17.850 && income <= 72.500)
            tax = bracket1 + (income - 17.850) * 0.15 - 893;
        else if (income > 72.500 && income <= 146.400)
            tax = bracket1 + bracket2 + (income - 72.500) * 0.25 - 8143;
        else if (income > 146.400 && income <= 223.050)
            tax = bracket1 + bracket2 + bracket3 + (income - 146.400) * 0.28 - 12.535;
        else if (income > 223.050 && income <= 398.350)
            tax = bracket1 + bracket2 + bracket3 + bracket4 + (income - 223.050) * 0.33 - 23.688;
        else if (income > 398.350 && income <= 450.000)
            tax = bracket1 + bracket2 + bracket3 + bracket4 + bracket5 + (income - 398.350) * 0.35 - 31.655;
        else if (income > 450.000)
            tax = bracket1 + bracket2 + bracket3 + bracket4 + bracket5 + bracket6 + (income - 450.000) * 0.396 - 52.355;
    
        owed = tax - paid;
    
        if (owed > 0)
            printf("Tax due is %.02f", owed);
        else if (owed < 0)
            printf("Refund is %.02f", owed);
    }
    

    同时检查括号2和3,奇怪的数字,我不相信正确的结果