【问题标题】:What should i put in the set and what should my condition be?我应该在套装中放什么,我的状况应该是什么?
【发布时间】:2016-04-20 20:17:00
【问题描述】:

计算用户输入的应税收入应缴纳的所得税。一定要包括错误检查以确保用户没有输入负数。还有一个图表

http://imgur.com/E5AqNxQ

让我陷入困境的是我的状况应该是什么,我是否声明了正确的事情以及应该是什么? 我有 将所得税、应纳税额申报为浮动

调用输入

调用集

调用输出

输入

写“输入应税收入”

进项应税收入

结束输入

设置

我不知道。

输出

帮帮我

【问题讨论】:

    标签: loops if-statement while-loop


    【解决方案1】:

    我不确定您用什么语言编写此代码,但这是您用 C 语言编写的解决方案。请记住,这是使用整数,而不是浮点数。所以答案将被截断。教科书中的问题说假设整数条目,因此我这样做了。

        int main()
    {
        printf("Please enter your income: ");
        int iIncome = 0;
        int iTaxAmount = 0;
        char iChecking = 0;
    
        //use a while loop with our scanf to make sure a valid number is input.
        while (iChecking == 0)
        {
            scanf("%d", &iIncome);
            if (iIncome <= 0)
            {
                printf("Please enter a positive, nonzero number\n");
                printf("Please enter your income: ");
            }
            else
            {
                iChecking = 1;
            }
        }
    
    
        if (iIncome < 50000)
        {
    
            iTaxAmount = iIncome * 0.05;
        }
        else if (iIncome < 100000 && iIncome >= 50000)
        {
            //set base amount
            iTaxAmount = 2500;
            int iTaxableOver50k = 0;
            //calculate taxable amount over 50k
            iTaxableOver50k = iIncome - 50000;
            //add base tax to percent value
            iTaxAmount = iTaxAmount + iTaxableOver50k * 0.07;
        }
        else if (iIncome >= 100000)
        {
            //set base tax amount
            iTaxAmount = 6000;
            int iTaxableOver100k = 0;
            //calculate taxable amount over 100k
            iTaxableOver100k = iIncome - 100000;
            //add base tax to percent value
            iTaxAmount = iTaxAmount + iTaxableOver100k*0.09;
        }
    
        printf("\nYou must pay: $%d in tax\n", iTaxAmount);
    
        return 0;
    }
    

    这是您使用浮点计算得出最终答案的解决方案。

    #include <stdio.h>
    
    int main()
    {
        printf("Please enter your income: ");
        int iIncome = 0;
        float iTaxAmount = 0.0f;
        char iChecking = 0;
    
        //use a while loop with our scanf to make sure a valid number is input.
        while (iChecking == 0)
        {
            scanf("%d", &iIncome);
            if (iIncome <= 0)
            {
                printf("Please enter a positive, nonzero number\n");
                printf("Please enter your income: ");
            }
            else
            {
                iChecking = 1;
            }
        }
    
    
        if (iIncome < 50000)
        {
    
            iTaxAmount = (float)iIncome * 0.05f;
        }
        else if (iIncome < 100000 && iIncome >= 50000)
        {
            //set base amount
            iTaxAmount = 2500;
            int iTaxableOver50k = 0;
            //calculate taxable amount over 50k
            iTaxableOver50k = iIncome - 50000;
            //add base tax to percent value
            iTaxAmount = iTaxAmount + (float)iTaxableOver50k * 0.07f;
        }
        else if (iIncome >= 100000)
        {
            //set base tax amount
            iTaxAmount = 6000;
            int iTaxableOver100k = 0;
            //calculate taxable amount over 100k
            iTaxableOver100k = iIncome - 100000;
            //add base tax to percent value
            iTaxAmount = iTaxAmount + (float)iTaxableOver100k*0.09f;
        }
    
    
        printf("\nYou must pay: $%.2f in tax\n", iTaxAmount);
    
        return 0;
    }
    

    【讨论】:

    • 糟糕它应该是伪代码。但是谢谢,多亏了这一点,我实际上有点明白我现在应该做的事情了。
    • 很高兴它有帮助!不过,这只是一件真正快速的事情,收入金额应该乘以 0.0 倍而不是 1.0 倍,因为您正在计算百分比金额,而不是添加到原始金额 - 我刚刚更新了帖子以反映这一点 :)
    猜你喜欢
    • 2012-12-08
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 2021-06-15
    • 2016-07-15
    相关资源
    最近更新 更多