Geethanjali College of Engineering and Technology
Geethanjali College of Engineering and Technology
ABSTRACT
PROJECT TITLE: Electricity bill generation
In C programming, electricity bill generation involves calculating the total cost
based on consumption and predefined rates. Utilize variables for units
consumed, rate per unit, and calculate the total cost using a simple formula.
Consider user input for consumption, apply conditional statements for
different rate slabs, and display the generated electricity bill.
#include <stdio.h>
int main() {
// Input
char name[50], address[100];
float prevReading, currReading, consumption, tariffRate, billAmount;
printf("Enter customer details:\n");
printf("Name: ");
gets(name); // Using gets for simplicity, not recommended in real programs
printf("Address: ");
gets(address);
printf("\nEnter meter readings:\n");
printf("Previous Reading: ");
scanf("%f", &prevReading);
printf("Current Reading: ");
scanf("%f", &currReading);
printf("\nEnter tariff rate (per unit): ");
scanf("%f", &tariffRate);
// Calculate Consumption
consumption = currReading - prevReading;
// Calculate Bill Amount
billAmount = consumption * tariffRate;
// Display Bill
printf("\n--- Electricity Bill ---\n");
printf("Customer Name: %s\n", name);
printf("Address: %s\n", address);
printf("Consumption: %.2f units\n", consumption);
printf("Bill Amount: $%.2f\n", billAmount);
return 0;
}
/**
* C program to calculate total electricity bill
*/
#include <stdio.h>
int main()
{
int unit;
float amt, total_amt, sur_charge;
/* Input unit consumed from user */
printf("Enter total units consumed: ");
scanf("%d", &unit);
/* Calculate electricity bill according to given conditions */
if(unit <= 50)
{
amt = unit * 0.50;
}
else if(unit <= 150)
{
amt = 25 + ((unit-50) * 0.75);
}
else if(unit <= 250)
{
amt = 100 + ((unit-150) * 1.20);
}
else
{
amt = 220 + ((unit-250) * 1.50);
}
/*
* Calculate total electricity bill
* after adding surcharge
*/
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;
printf("Electricity Bill = Rs. %.2f", total_amt);
return 0;
}
OUTPUT
Electricity bill generation in c using structures