Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <stdio.

h>

// Function to calculate the price of each fruit


float calculatePrice(float apple_qty, float mango_qty, float grapes_qty, float
strawberries_qty) {
float apple_price = 50.0; // Price of 1 kg apple
float mango_price = 80.0; // Price of 1 kg mango
float grapes_price = 60.0; // Price of 1 kg grapes
float strawberries_price = 100.0; // Price of 1 kg strawberries

float total_price = (apple_qty * apple_price) + (mango_qty * mango_price) +


(grapes_qty * grapes_price) + (strawberries_qty * strawberries_price);

return total_price;
}

// Function to calculate discount


float calculateDiscount(float total_price) {
float discount_price = total_price * 0.1; // 10% discount

return discount_price;
}

// Function to calculate final bill


void calculateBill(float discount_price, float total_price) {
float final_price = total_price - discount_price;
printf("Total price before discount: %.2f\n", total_price);
printf("Discount: %.2f\n", discount_price);
printf("Final bill after discount: %.2f\n", final_price);
}

int main() {
float apple_qty, mango_qty, grapes_qty, strawberries_qty;

printf("Enter the quantity of Apples (in kg): ");


scanf("%f", &apple_qty);
printf("Enter the quantity of Mangoes (in kg): ");
scanf("%f", &mango_qty);
printf("Enter the quantity of Grapes (in kg): ");
scanf("%f", &grapes_qty);
printf("Enter the quantity of Strawberries (in kg): ");
scanf("%f", &strawberries_qty);

float total_price = calculatePrice(apple_qty, mango_qty, grapes_qty,


strawberries_qty);

if (total_price > 1500) {


float discount_price = calculateDiscount(total_price);
calculateBill(discount_price, total_price);
} else {
printf("Total price: %.2f\n", total_price);
}

return 0;
}

You might also like