Site icon TestingDocs.com

C Program to Calculate Sales Tax

Overview

In this post, we will develop a C program to Calculate the Sales tax of a purchased product. However, the shop runs some discounts on household items that need to be calculated before the Sales tax computation.

Problem Statement

Write a C program to calculate the SalesTax, Discount, and Total Price. Below are the program rules:

Program Rules:

Sales Tax on Household Items is 12%. Household items have a discount of 10%

Sale Tax on all other items in the shop is 18%
If there is a discount, apply the discount before SalesTax.

Display the purchase cost, discount amount(household items), sales tax amount, total price.

C Program

#include
/**********************************************************
 Description: C Program to calculate SalesTax
 www.TestingDocs.com
***********************************************************/
//  Program Rules:
//  Assume SalesTax = 18%
//  If HouseHold Item = 12% - House hold items have discount of 10%
//  Apply Discount before SalesTax.
void main()
{
    double productPrice, salesTax;
    double houseHoldDiscount;
    double Total,discountedTotal ;
    double salesTaxPercent,discountPercent;
    char hItem;
    printf("Enter the price of purchased Product :$ ");
    scanf("%lf", &productPrice);
    printf("Is the product household item?[Y/N] :");
    scanf(" %c", &hItem);
    printf("-----------------------------------------------------\n");

    printf("Total purchases: $ %.2lf \n", productPrice);
    if(hItem =='Y' || hItem =='y')
    {
        //Household ITems
        houseHoldDiscount =  productPrice*0.10;
        printf("HouseHold Discount (10%%) : $ %.2lf \n", houseHoldDiscount);
        discountedTotal = productPrice - houseHoldDiscount;
        printf("Total After Discount : $ %.2lf \n", discountedTotal);
        salesTax =  discountedTotal*0.12;
        printf("Sales Tax(12%%) : $ %.2lf \n", salesTax);
        Total = discountedTotal + salesTax ;
        printf("Grand Total : $ %.2lf \n", Total);
    }
    else
    {
        // Others - Non-Household Items
        salesTax =  productPrice*0.18;
        printf("Sales Tax(18%%) : $ %.2lf \n", salesTax);
        Total = productPrice + salesTax ;
        printf("Grand Total : $ %.2lf \n", Total);
    }
    printf("-----------------------------------------------------\n");
}

Sample Output

 

Testcases

Happy path Testcase 1:(Household item)

Enter the price of purchased Product :$ 200
Is the product household item?[Y/N] :Y
—————————————————–
Total purchases: $ 200.00
HouseHold Discount (10%) : $ 20.00
Total After Discount : $ 180.00
Sales Tax(12%) : $ 21.60
Grand Total : $ 201.60
—————————————————–

Happy path Testcase 2:( Non-household item)

Enter the price of purchased Product :$ 220
Is the product household item?[Y/N] :N
—————————————————–
Total purchases: $ 220.00
Sales Tax(18%) : $ 39.60
Grand Total : $ 259.60
—————————————————–

 

Exit mobile version