P027.c¶
Problem Statement
Purchase Discount on Discount on Amount Laptop Desktop -------- ----------- ----------- Upto 20k 3.0% 5.0% 20001 - 50k 5.0% 7.5% 50001 - 75k 7.5% 10.5% more than 75k 10.0% 15.0% WAP to input amount of purchase and type of purchase ('L' : laptop, 'D' : desktop) and display the discount amount and the discounted price (Net Amount).
Metadata¶
| Property | Detail |
|---|---|
| Author | Amit Dutta amitdutta4255@gmail.com |
| Date | 12 Dec 2025 |
| License | MIT License (See the LICENSE file for details) |
| Difficulty | Beginner (index: 1 / 10) |
Concepts¶
Beta Feature
This concept detection system is still in beta and may occasionally show incorrect or incomplete results.
- Recursion
- Pointers
Actions¶
You can print or save this file by opening Raw and using your browser.
Source Code¶
#include <stdio.h>
#include <ctype.h>
int main()
{
double principal_amount, desktop_discount, laptop_discount, discount_amount, discounted_price;
char choice;
printf("Enter the purchase amount : ");
scanf("%lf", &principal_amount);
printf("Type of purchase ('L' : Laptop, 'D' : Desktop) : ");
scanf(" %c", &choice);
choice = toupper(choice);
if (principal_amount <= 20000)
{
laptop_discount = 0.03;
desktop_discount = 0.05;
}
else if (principal_amount > 20000 && principal_amount <= 50000)
{
laptop_discount = 0.05;
desktop_discount = 0.075;
}
else if (principal_amount > 50000 && principal_amount <= 75000)
{
laptop_discount = 0.075;
desktop_discount = 0.105;
}
else if (principal_amount > 75000)
{
laptop_discount = 0.1;
desktop_discount = 0.15;
}
switch (choice)
{
case 'L':
discount_amount = principal_amount * laptop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
case 'D':
discount_amount = principal_amount * desktop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
default:
printf("\nInvalid Input.");
return 1;
}
return 0;
}
Explanation¶
Explain with AI
Copy the prompt below and paste it into any AI assistant.
You are explaining a C programming code to a beginner.
STRICT RULES:
- Only use the given code. Do NOT assume anything not present.
- Do NOT add extra examples.
- Keep explanation clear and short.
- If something is unclear, say "Not clear from code".
- Follow the exact format below. Do NOT change headings.
FORMAT:
[START]
## What it does
(Explain the overall purpose in 1-2 sentences)
## Step-by-step
(Explain how the code works in steps, simple language)
## Key Concepts
(List concepts like loop, condition, function, etc.)
## Notes
(Mention any limitations, errors, or assumptions)
[END]
CODE (P027.c):
#include <stdio.h>
#include <ctype.h>
int main()
{
double principal_amount, desktop_discount, laptop_discount, discount_amount, discounted_price;
char choice;
printf("Enter the purchase amount : ");
scanf("%lf", &principal_amount);
printf("Type of purchase ('L' : Laptop, 'D' : Desktop) : ");
scanf(" %c", &choice);
choice = toupper(choice);
if (principal_amount <= 20000)
{
laptop_discount = 0.03;
desktop_discount = 0.05;
}
else if (principal_amount > 20000 && principal_amount <= 50000)
{
laptop_discount = 0.05;
desktop_discount = 0.075;
}
else if (principal_amount > 50000 && principal_amount <= 75000)
{
laptop_discount = 0.075;
desktop_discount = 0.105;
}
else if (principal_amount > 75000)
{
laptop_discount = 0.1;
desktop_discount = 0.15;
}
switch (choice)
{
case 'L':
discount_amount = principal_amount * laptop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
case 'D':
discount_amount = principal_amount * desktop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
default:
printf("\nInvalid Input.");
return 1;
}
return 0;
}