{"id":19168,"date":"2017-03-08T13:11:36","date_gmt":"2017-03-08T13:11:36","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=19168"},"modified":"2021-03-20T12:46:39","modified_gmt":"2021-03-20T12:46:39","slug":"c-program-to-calculate-sales-tax","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/c-program-to-calculate-sales-tax\/","title":{"rendered":"C Program to Calculate Sales Tax"},"content":{"rendered":"<h3>Overview<\/h3>\n<p>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.<\/p>\n<h3>Problem Statement<\/h3>\n<p>Write a C program to calculate the SalesTax, Discount, and Total Price. Below are the program rules:<\/p>\n<p>Program Rules:<\/p>\n<p>Sales Tax on Household Items is <strong>12%<\/strong>. Household items have a discount of <strong>10%<\/strong><\/p>\n<p>Sale Tax on all other items in the shop is <strong>18%<\/strong><br \/>\nIf there is a discount, apply the discount before SalesTax.<\/p>\n<p>Display the purchase cost, discount amount(household items), sales tax amount, total price.<\/p>\n<h3>C Program<\/h3>\n<pre>#include\r\n\/**********************************************************\r\n Description: C Program to calculate SalesTax\r\n www.TestingDocs.com\r\n***********************************************************\/\r\n\/\/  Program Rules:\r\n\/\/  Assume SalesTax = 18%\r\n\/\/  If HouseHold Item = 12% - House hold items have discount of 10%\r\n\/\/  Apply Discount before SalesTax.\r\nvoid main()\r\n{\r\n    double productPrice, salesTax;\r\n    double houseHoldDiscount;\r\n    double Total,discountedTotal ;\r\n    double salesTaxPercent,discountPercent;\r\n    char hItem;\r\n    printf(\"Enter the price of purchased Product :$ \");\r\n    scanf(\"%lf\", &amp;productPrice);\r\n    printf(\"Is the product household item?[Y\/N] :\");\r\n    scanf(\" %c\", &amp;hItem);\r\n    printf(\"-----------------------------------------------------\\n\");\r\n\r\n    printf(\"Total purchases: $ %.2lf \\n\", productPrice);\r\n    if(hItem =='Y' || hItem =='y')\r\n    {\r\n        \/\/Household ITems\r\n        houseHoldDiscount =  productPrice*0.10;\r\n        printf(\"HouseHold Discount (10%%) : $ %.2lf \\n\", houseHoldDiscount);\r\n        discountedTotal = productPrice - houseHoldDiscount;\r\n        printf(\"Total After Discount : $ %.2lf \\n\", discountedTotal);\r\n        salesTax =  discountedTotal*0.12;\r\n        printf(\"Sales Tax(12%%) : $ %.2lf \\n\", salesTax);\r\n        Total = discountedTotal + salesTax ;\r\n        printf(\"Grand Total : $ %.2lf \\n\", Total);\r\n    }\r\n    else\r\n    {\r\n        \/\/ Others - Non-Household Items\r\n        salesTax =  productPrice*0.18;\r\n        printf(\"Sales Tax(18%%) : $ %.2lf \\n\", salesTax);\r\n        Total = productPrice + salesTax ;\r\n        printf(\"Grand Total : $ %.2lf \\n\", Total);\r\n    }\r\n    printf(\"-----------------------------------------------------\\n\");\r\n}\r\n\r\n<\/pre>\n<h3>Sample Output<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19176\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax.png\" alt=\"C Program Sales Tax\" width=\"1920\" height=\"930\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax-300x145.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax-1024x496.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax-768x372.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Program-Sales-Tax-1536x744.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Testcases<\/h3>\n<p>Happy path Testcase 1:(Household item)<\/p>\n<p>Enter the price of purchased Product :$ 200<br \/>\nIs the product household item?[Y\/N] :Y<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nTotal purchases: $ 200.00<br \/>\nHouseHold Discount (10%) : $ 20.00<br \/>\nTotal After Discount : $ 180.00<br \/>\nSales Tax(12%) : $ 21.60<br \/>\nGrand Total : $ 201.60<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>Happy path Testcase 2:( Non-household item)<\/p>\n<p>Enter the price of purchased Product :$ 220<br \/>\nIs the product household item?[Y\/N] :N<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nTotal purchases: $ 220.00<br \/>\nSales Tax(18%) : $ 39.60<br \/>\nGrand Total : $ 259.60<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19180 size-full\" title=\"TestCase C Program SalesTax\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax.png\" alt=\"TestCase C Program SalesTax\" width=\"1730\" height=\"924\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax.png 1730w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax-300x160.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax-1024x547.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax-768x410.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestCase-C-Program-SalesTax-1536x820.png 1536w\" sizes=\"auto, (max-width: 1730px) 100vw, 1730px\" \/><\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-19168\" data-postid=\"19168\" class=\"themify_builder_content themify_builder_content-19168 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[188],"tags":[],"class_list":["post-19168","post","type-post","status-publish","format-standard","hentry","category-c-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=19168"}],"version-history":[{"count":10,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19168\/revisions"}],"predecessor-version":[{"id":19553,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19168\/revisions\/19553"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=19168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=19168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=19168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}