Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

คำนวณจำนวนเงินรวมภาษี ด้วย Assignment Operator ใน C

โจทย์

รับจำนวนเงิน (ดอลลาร์) แล้วแสดงผลรวมหลังเพิ่มภาษี 18%

ตรรกะ

value = money + (money * 0.18);

โปรแกรมที่ 1: ภาษี 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\n", value);
    return 0;
}

ผลลัพธ์

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

โปรแกรมที่ 2: ภาษี 20%

#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\n", value);
    return 0;
}

ผลลัพธ์

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