首頁  >  文章  >  後端開發  >  使用賦值運算子計算有稅金額的C程序

使用賦值運算子計算有稅金額的C程序

PHPz
PHPz轉載
2023-08-26 13:53:22608瀏覽

使用賦值運算子計算有稅金額的C程序

問題

寫一個 C 程序,輸入美元金額,然後加上 18% 的稅金來顯示金額。

解決方案

讓我們考慮餐廳人員在顧客的每張帳單上加收 18% 的稅金。

用於計算稅的邏輯是-

value=(money (money * 0.18));

這筆錢應該乘以18 %並添加到錢中,然後餐廳人員可以從顧客那裡收到含稅的金額。

範例

 現場示範

#include<stdio.h>
int main(){
   float money,value;
   printf("enter the money with dollar symbol:");
   scanf("%f",&money);
   value=(money + (money * 0.18));
   printf("amount after adding tax= %f</p><p>",value);
   return 0;
}

輸出

enter the money with dollar symbol:250$
amount after adding tax= 295.000000

範例

讓我們透過更改百分比來考慮相同的程式-

 現場示範

#include<stdio.h>
int main(){
   float money,value;
   printf("enter the money with dollar symbol:");
   scanf("%f",&money);
   value=(money + (money * 0.20));
   printf("amount after adding tax= %f</p><p>",value);
   return 0;
}

輸出

enter the money with dollar symbol:250$
amount after adding tax= 300.000000

以上是使用賦值運算子計算有稅金額的C程序的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除