2016-04-20 133 views
0

计算用户输入的应税收入所得税。一定要包括错误检查,以确保用户不输入负数。那里有一个图表,以及
我应该在场景中放什么,我的状态应该是什么?

http://imgur.com/E5AqNxQ

什么使我的卡是什么东西应该是我的病情,我是宣告正确的事情,应该是什么套? 我有 声明incometax,taxdue,浮法

调用输入

呼叫建立

调用输出

输入

写 “进入应纳税所得额”

输入应税收入

末输入

设置

我不知道。

输出

帮我

回答

0

我不知道用什么语言你在写这个,但这里是你在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

糟糕它应该是psuedocode。但是,谢谢,我真的有点得到我应该做的,现在得到了。 – usedtobeapotato

+0

很高兴它帮助!只是一个真正的快速的事情,收入金额应该乘以0.0x而不是1.0x,因为你正在计算%金额,而不是添加到原始金额 - 我刚刚更新了帖子,以反映这:) – Swemoph

相关问题