0% found this document useful (0 votes)
31 views8 pages

Geethanjali College of Engineering and Technology

The document discusses generating electricity bills in C programming. It explains taking user input for customer details and meter readings, calculating consumption by subtracting previous from current reading, using conditional statements to apply different rates based on consumption slabs to calculate the bill amount, and outputting the customer details and final bill. It provides examples of code implementation using structures and functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views8 pages

Geethanjali College of Engineering and Technology

The document discusses generating electricity bills in C programming. It explains taking user input for customer details and meter readings, calculating consumption by subtracting previous from current reading, using conditional statements to apply different rates based on consumption slabs to calculate the bill amount, and outputting the customer details and final bill. It provides examples of code implementation using structures and functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

GEETHANJALI COLLEGE OF ENGINEERING AND TECHNOLOGY

UGC AUTONOMOUS, ACCREDITED BY NAAC, ‘ A’ GRADE,

CHEERYAL(V), KEESARA(M), MEDCHAL DISTRICT-501301

PROGRAMMING FOR PROBLEM SOLVING (PPS)


FIRST YEAR,SEMISTER-1

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.

In a C program for electricity bill generation, you would typically


Input: Take user inputs such as customer details (name, address), meter
readings (previous and current), and tariff rates.
Calculate Consumption: Determine the electricity consumption by subtracting
the previous meter reading from the current reading.
Calculate Bill Amount: Use the consumption and tariff rates to calculate the bill
amount. This may involve different rates for various consumption slabs.
Display Bill: Output the customer details and the calculated bill amount.
Here's a simplified example:
Note: This is a basic example and may not cover all edge cases or error handling. Always validate and
sanitize user inputs in real-world applications.

#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;
}

FLOW CHART MAIN MODULE


C PROGRAM

/**
* 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

//generating electricity bill using structure in C


#include<stdio.h>
/** This block defines the structure Bill having
fields for first name, last name, address,
previous unit and present unit. The structure
must be defined before main function */
struct Bill{
char firstName[10];
char lastName[10];
char Address[20];
float previousUnit;
float presentUnit;
};
/** This is the function definition that
calculates the cost. Here structure is passed
as an argument */
float generateBill(struct Bill temp){
float diff;
diff = temp.presentUnit - temp.previousUnit;
if(diff > 20){
return diff*4.75;
}else{
return 20*4.75+(diff-20)*7.75;
}
}
int main(){
struct Bill bill; /Declaration of structure variable/
printf("Fill up the following: \n");
printf("First Name: ");
fgets(bill.firstName); //accessing member
printf("Last Name: ");
fgets(bill.lastName);
printf("Address: ");
fgets(bill.Address);
printf("Previous Unit: ");
scanf("%f",&bill.previousUnit);
printf("Present Unit: ");
scanf("%f",&bill.presentUnit);
printf("\a\n\n**********Electricity Bill**************\n\n\a");
printf("Name: %s %s",bill.firstName,bill.lastName);
printf("\nAddress: %s",bill.Address);
printf("\nPrevious Unit: %.3f Current Unit:
%.3f",bill.previousUnit,bill.presentUnit);
printf("\nCost: %.3f\n\n", generateBill(bill));
return 0;
}
THANK YOU
TEAMMEMBERS
23R11A6288-S-Vishwanth
23R11A6271-K.PRAJWAL REDDY
23R11A6267-G GANESH

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy