C program for electricity board charges.

Q40. An electricity board charges according to following rates:
For the first 100 units – 40 P per unit  (P-Paise)

For the next 200 units – 50 P per unit

Beyond 300 units – 60 P per unit.

All users are charged meter charge also which is R50/-.

Write a program to read the names of users and number of units consumed, and print out the charges with names.

Ans.

#include<stdio.h>  //for standard input output

#include<conio.h>  //for clrscr();

 

//A class called customer to hold all the information related to customer

struct customer

{

char name[20]

int units;

float charge;

}x[3];

//Sturcture Variable

//End of Structure

 

 

//A function of to read name and number of units of customer

void read(int i)

{

printf(“\n Enter the name of customer: “);

scanf(“%s”,&x[i].name);

printf(“\n Enter the number of units consumed: “);

scanf(“%d”,&x[i].units);

}

 

//A function to calculate the charge of customer

void calculate(int i)

{

if(x[i].units<=100)

{

x[i].charge=40;

}

else

{

if(x[i].units<=300)

{

x[i].charge=50;

}

else

{

x[i].charge=60;

}

}

}

 

//A function to print the details of cutomers

void print(int i)

{

printf(“\n Customer name: %s”,x[i].name);

printf(“\n Number of units consumed: %d”,x[i].units);

printf(“\n Charge: Rs. 50.%f”,x[i].charge);

}

 

//Main function

void main()

{

int i;

clrscr();  //for clear screen

 

 

//for loop to read the details of 3 customers

for(i=0;i<3;i++)

{

read(i);

}

 

//for loop to print the details of 3 customers

for (i=0;i<3;i++)

{

calculate(i);

print(i);

}

 

//To hold the screen

getch();

 

}

//End of main() function

 

Output:

 

Enter the name of customer: Anita

Enter the number of units consumed: 200

Enter the name of customer: Babita

Enter the number of units consumed: 350

Enter the name of customer: Ganesha

Enter the number of units consumed: 890

 

Customer name: Anita

Number of units consumed: 200

Charge: Rs. 50.50.000000

Customer name: Babita

Number of units consumed: 350

Charge: Rs. 50.60.000000

Customer name: Ganesha

Number of units consumed: 890

Charge: Rs. 50.60.000000

Leave a Reply

Your email address will not be published. Required fields are marked *

956 Views
%d bloggers like this: