bsc

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

root / semester_1 / tuition-c / P027.c

P027.c (2175B)


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