程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> printf-(c語言)利用%ld讀取double類型,程序可以運行,但是結果是很大的負數?

printf-(c語言)利用%ld讀取double類型,程序可以運行,但是結果是很大的負數?

編輯:編程綜合問答
(c語言)利用%ld讀取double類型,程序可以運行,但是結果是很大的負數?

#include
#define TAX_1 17850
#define TAX_2 23900
#define TAX_3 29750
#define TAX_4 14875
#define TAXRATE_1 0.15
#define TAXRATE_2 0.28
int main(void)
{
double taxsalary,taxpay;
int n;
printf("Please enter your taxsalary(q to quit):\n");
while(scanf("%ld",&taxsalary)==1)
{
printf("please enter your kinds of tax(from 1 to 4):\n");
printf("1)single tax: $17850 %15 more:%28\n");
printf("2)owner tax: $23900 %15 more:%28\n");
printf("3)double(together) tax: $29700 %15 more:%28\n");
printf("4)double(divorce) tax: $23900 %15 more:%28\n");
scanf("%d",&n);
if (n==1)
{
if(taxsalary<=TAX_1)
{
taxpay=taxsalary*TAXRATE_1;
printf("taxpay:%ld\n",taxpay);

            }

        else
          {
            taxpay=TAX_1*TAXRATE_1+(taxsalary-TAX_1)*TAXRATE_2;
                printf("taxpay:%ld\n",taxpay);
          }

    }
    if (n==2)
    {
        if (taxsalary<=TAX_2)
        {
            taxpay=taxsalary*TAXRATE_1;
                printf("taxpay:%ld\n",taxpay);
        }
        else
        {
            taxpay=TAX_2*TAXRATE_1+(taxsalary-TAX_2)*TAXRATE_2;
            printf("taxpay:%ld\n",taxpay);
        }

    }
    if (n==3)
    {
        if (taxsalary<=TAX_3)
        {
            taxpay=taxsalary*TAXRATE_1;
                printf("taxpay:%ld\n",taxpay);
        }
        else
        {
            taxpay=TAX_3*TAXRATE_1+(taxsalary-TAX_3)*TAXRATE_2;
                printf("taxpay:%ld\n",taxpay);
        }

    }
    if (n==4)
    {
        if (taxsalary<=TAX_4)
        {
            taxpay=taxsalary*TAXRATE_1;
                printf("taxpay:%ld\n",taxpay);
        }
        else
        {
            taxpay=TAX_4*TAXRATE_1+(taxsalary-TAX_4)*TAXRATE_2;
                printf("taxpay:%ld\n",taxpay);
        }
    }
    printf("Please enter your taxsalary:(q to quit)\n");


}
return 0;

}

最佳回答:


非常感謝,又仔細查了一下。是%lf,記錯了,

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved