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

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)

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);


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

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


BPOPS103/203 Principles of Programming using C Lab

Flowchart:

Program:
#include <stdio.h>
void main()
{

char name[10];

float unit, metercharge = 100;


printf("Enter your name:");

scanf("%s", name);
printf("Enter electricity units consumed:");
scanf("%f", &unit);
Dept. of AI & DS, SMVITM, Bantakal Page 2
BPOPS103/203 Principles of Programming using C Lab

if(unit <= 200)

metercharge = metercharge + (unit * 0.80);

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


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

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 3

You might also like