0% found this document useful (0 votes)
45 views

POP Using C - VTU Lab Program-3

The document describes an electricity billing program that calculates charges based on usage tiers and includes a minimum fee and surcharge. It provides the rate structure, explains the algorithm to calculate the bill amount, includes a flowchart, and shows sample code and output.

Uploaded by

vandana u
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

POP Using C - VTU Lab Program-3

The document describes an electricity billing program that calculates charges based on usage tiers and includes a minimum fee and surcharge. It provides the rate structure, explains the algorithm to calculate the bill amount, includes a flowchart, and shows sample code and output.

Uploaded by

vandana u
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

BPOPS103/203

Principles of Programming using C Lab

3. An electricity board charges the following rates for the use of electricity: for the first 200
units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1 per unit. All
users are charged a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400,
then an additional surcharge of 15% of the total amount is charged. Write a program to read the
name of the user, the number of units consumed, and print out the charges.

Algorithm:

Step 1: START
Step 2 : Read the name of the user
Step 3: Read the number of units consumed
Step 4: Initialize the minimum meter charge as 100

Step 5: if(unit <= 200) then

Compute metercharge = metercharge + (unit * 0.80)

Dept. of AI & DS, SMVITM, Bantakal Page 1


BPOPS103/203
Principles of Programming using C Lab

else if(unit > 200 && unit <= 300)

Compute metercharge = metercharge + (200 * 0.80) + ((unit - 200) * 0.90)

else if(unit > 300)

Compute metercharge = metercharge + (200 * 0.80) + (100 * 0.90) + ((unit - 300) * 1)

Step 6: Check if(metercharge>=400)

Compute metercharge = metercharge + (metercharge * 0.15);

Dept. of AI & DS, SMVITM, Bantakal Page 2


BPOPS103/203
Principles of Programming using C Lab

Step 7: Print name, units of electricity consumed and meter charge


Step 9: STOP

Flowchart:

Dept. of AI & DS, SMVITM, Bantakal Page 3


BPOPS103/203
Principles of Programming using C Lab

Program:

#include <stdio.h>
void main()

Dept. of AI & DS, SMVITM, Bantakal Page 4


BPOPS103/203
Principles of Programming using C Lab

char name[10];

float unit, metercharge = 100;


printf("Enter your name:");

scanf("%s", name);

printf("Enter electricity units consumed:");


scanf("%f", &unit);

if(unit <= 200)

metercharge = metercharge + (unit * 0.80);

else if(unit > 200 && unit <= 300)

Dept. of AI & DS, SMVITM, Bantakal Page 5


BPOPS103/203
Principles of Programming using C Lab

metercharge = metercharge + (200 * 0.80) + ((unit - 200) * 0.90);


else if(unit > 300)

metercharge = metercharge + (200 * 0.80) + (100 * 0.90) + ((unit - 300) * 1);

if(metercharge >= 400)

metercharge = metercharge + (metercharge * 0.15);

printf("\n Name: %s \n Number of unit consumed: %f \n MeterCharge: %f \n", name, unit,


metercharge);

}
Command to execute the Program:
$ gcc lab3.c -lm
$ ./a.out

Output:

Case 1:

Enter your name: Keerthi

Dept. of AI & DS, SMVITM, Bantakal Page 6


BPOPS103/203
Principles of Programming using C Lab

Enter electricity units consumed: 200

Name: Keerthi

Number of unit consumed: 200

MeterCharge: 260.000

Case 2:

Enter your name: Anika

Enter electricity units consumed: 400

Name: Anika

Number of unit consumed: 400 MeterCharge : 517.50

Dept. of AI & DS, SMVITM, Bantakal Page 7

You might also like