2016-04-20 179 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

相關問題