Home Tutorials C Programs Tutorial C program to calculate discount
C program to calculate discount

C program to calculate discount


C Practical Logic • Conditionals

Program to Calculate a 50% Discount

Learn how to apply conditional business logic using an if-else statement. This program checks if a student's or customer's purchase amount exceeds ₹8,000 to trigger a flat 50% discount deduction.

discount_calc.c
C Language
#include <stdio.h> int main() { float totalAmount; float discountPercentage; float discountAmount; float finalAmount; // Get total purchase amount from the user printf("Enter the total amount purchased: "); scanf("%f", &totalAmount); // Check whether the amount is strictly greater than 8000 if (totalAmount > 8000) { discountPercentage = 50; discountAmount = totalAmount * (discountPercentage / 100); } else { discountPercentage = 0; discountAmount = 0; } // Calculate final amount finalAmount = totalAmount - discountAmount; // Display the structured billing output printf("\n----- BILL DETAILS -----\n"); printf("Total Amount Purchased : %.2f\n", totalAmount); printf("Discount Percentage : %.2f%%\n", discountPercentage); printf("Discount Amount : %.2f\n", discountAmount); printf("Final Amount to Pay : %.2f\n", finalAmount); return 0; }

💻 Program Execution Trace Cases

Example 1

Condition Met (Amount > ₹8,000)

Input:
Enter the total amount purchased: 10000
Console Output:
----- BILL DETAILS -----
Total Amount Purchased : 10000.00
Discount Percentage    : 50.00%
Discount Amount        : 5000.00
Final Amount to Pay    : 5000.00
Example 2

Condition Fails (Amount < = ₹8,000)

Input:
Enter the total amount purchased: 7000
Console Output:
----- BILL DETAILS -----
Total Amount Purchased : 7000.00
Discount Percentage    : 0.00%
Discount Amount        : 0.00
Final Amount to Pay    : 7000.00

⚠️ Important Structural Boundary Warning

Because this logic path checks for values strictly greater than 8,000, typing exactly 8000 will map directly to the else block, resulting in 0% discount.

To explicitly include the value of ₹8,000 in the discount criteria, alter the statement conditional expression operator:

Strict Exclusion if (totalAmount > 8000)
Inclusive Check if (totalAmount >= 8000)
Example