Write a program in C to calculate and print the Electricity bill of a given customer.



QUESTION

Write a program in C to calculate and print the Electricity bill of a given customer. The customer id., name, and unit consumed by the   

user should be taken from the keyboard and display the total amount to pay to the customer. The charge is as follow: Go to the editor  

 Unit Charge/unit 

up to 199 @1.20  

200 and above but less than 400 @1.50  

400 and above but less than 600 @1.80  

600 and above @2.00  

If the bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill should be Rs. 100/-  


program


#include <stdio.h>

void main()

{

    int idel;

    float tc1tc2tctc3tc4tca;

    char name;

    printf("enter your name(only first letter of your name): ");

    scanf("%c", &name);

    printf("enter your customer id: ");

    scanf("%d", &id);

    printf("enter a unit of consumed Electricity: ");

    scanf("%d", &el);

    if (el >= 0 && el <= 199)

    {

        tc1 = 1.20 * el;

        printf("your bill is %2.f$"tc1);
    }

    else if (el >= 200 && el <= 399)

    {

        tc1 = 1.20 * 199;

        tc2 = 1.50 * (el - 199);

        tc = (tc1 + tc2);

        tca = (tc * 15 / 100) + tc;

        printf("your bill is %f $"tca);
    }

    else if (el >= 400 && el <= 599)

    {

        tc1 = 1.20 * 199;

        tc2 = 1.50 * 200;

        tc3 = 1.80 * (el - 399); // 190.8 + 238.8 + 300

        tc = (tc1 + tc2 + tc3);

        tca = (tc * 15 / 100) + tc;

        printf("your bill is %f$"tca);
    }

    else if (el >= 600)

    {

        tc1 = 1.20 * 199;

        tc2 = 1.50 * 200;

        tc3 = 1.80 * 599;

        tc4 = 2.00 * (el - 999);

        tc = (tc1 + tc2 + tc3 + tc4); //  238.8 + 300 + 1078.2 + 2 = 1619

        tca = (tc * 15 / 100) + tc// ((1619 *15/100) + 1619) = 242.85 + 1619 = 1861.85

        printf("your bill is %f$"tca);
    }

    else

    {

        printf("program execute!");
    }
}

OUTPUT
enter your name(only first letter of your name): a 
enter your customer id: 145
enter a unit of consumed Electricity: 1450
your bill is 2896.850098$

Follow our page for regular updates.

0 Comments