2007年7月21日 星期六

[C]TAX範例

這是簡單TAX的範例,參考一下!!
-----------------------------------------------------
#include /*輸出入函式標頭檔*/
#include
#define msg "含稅金額:" /*提示訊息*/
#define tax_rate 0.05 /*稅率*/
int price=2000; /*宣告全域變數,並設定初值*/
float get_tax(void); /*自定函式原型*/
int main(void) /*主程式區*/
{
float total; /*宣告區域變數,資料型別為浮點數*/
total = price + get_tax(); /*總價=售價+稅金*/
printf("%s %.2f\n",msg,total);
/*
%s及%.2f為轉換字元,msg取代%s,total取代%.2f
%.2f顯示小數點後2位,整數位不變
*/
getche(); /*列印到畫面上*/
return 0;
}

float get_tax() /*計算稅金*/
{
float tax;
tax=price*tax_rate;
return(tax); /*將tax傳回main()主函式*/
}

--好康廣告--

1 則留言:

匿名 提到...

cow.....你又開始寫C++了喔...

  加入書籤: HemiDemi Yahoo! My Web Google Bookmarks technorati 收進你的MyShare個人書籤 Del.icio.us
Related Posts Plugin for WordPress, Blogger...