bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

P027.c (2366B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /*  Purchase        Discount on     Discount on
      9      Amount            Laptop         Desktop
     10     --------        -----------     -----------
     11     Upto 20k            3.0%            5.0%
     12     20001 - 50k         5.0%            7.5%
     13     50001 - 75k         7.5%           10.5%
     14     more than 75k      10.0%           15.0%
     15 WAP to input amount of purchase and type of purchase ('L' : laptop, 'D' : desktop)
     16 and display the discount amount and the discounted price (Net Amount).
     17 */
     18 // This code has not been compiled.
     19 // If you find any issues, please create a new issue on GitHub regarding them.
     20 
     21 #include <stdio.h>
     22 #include <ctype.h>
     23 int main()
     24 {
     25     double principal_amount, desktop_discount, laptop_discount, discount_amount, discounted_price;
     26     char choice;
     27     printf("Enter the purchase amount : ");
     28     scanf("%lf", &principal_amount);
     29     printf("Type of purchase ('L' : Laptop, 'D' : Desktop) : ");
     30     scanf(" %c", &choice);
     31     choice = toupper(choice);
     32     if (principal_amount <= 20000)
     33     {
     34         laptop_discount = 0.03;
     35         desktop_discount = 0.05;
     36     }
     37     else if (principal_amount > 20000 && principal_amount <= 50000)
     38     {
     39         laptop_discount = 0.05;
     40         desktop_discount = 0.075;
     41     }
     42     else if (principal_amount > 50000 && principal_amount <= 75000)
     43     {
     44         laptop_discount = 0.075;
     45         desktop_discount = 0.105;
     46     }
     47     else if (principal_amount > 75000)
     48     {
     49         laptop_discount = 0.1;
     50         desktop_discount = 0.15;
     51     }
     52     switch (choice)
     53     {
     54     case 'L':
     55         discount_amount = principal_amount * laptop_discount;
     56         discounted_price = principal_amount - discount_amount;
     57         printf("\nDiscount Amount : %g"
     58                "\nDiscounted Price : %g",
     59                discount_amount, discounted_price);
     60         break;
     61     case 'D':
     62         discount_amount = principal_amount * desktop_discount;
     63         discounted_price = principal_amount - discount_amount;
     64         printf("\nDiscount Amount : %g"
     65                "\nDiscounted Price : %g",
     66                discount_amount, discounted_price);
     67         break;
     68     default:
     69         printf("\nInvalid Input.");
     70         return 1;
     71     }
     72     return 0;
     73 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror