Coding Practice

Write a C program to input electricity unit charges and calculate total electricity bill

Input electricity unit charges and calculate total electricity bill

Calculate total electricity bill according to the given condition:

For first 50 units Tk. 1.50/unit
For next 100 units Tk. 2.25/unit
For next 100 units Tk. 3.00/unit
For unit above 250 Tk. 3.75/unit

An additional surcharge of 20% is added to the bill

Sample Output
Enter unit: 111

Total cost: 399.60


Process returned 0 (0x0)   execution time : 1.793 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    float unit, surcharge, taka;
 
    printf("Enter unit: ");
    scanf("%f", &unit);
 
    if(unit >=1 && unit <= 50)
    {
        //For first 50 units Tk. 1.50/unit
        taka = unit * 1.5;
        surcharge = taka * 0.2; //Surcharge 20%
        taka = taka + surcharge;
    }
    else if(unit >=51 && unit <=100)
    {
        //For next 100 units Tk. 2.25/unit
        taka = unit * 2.25;
        surcharge = taka * 0.2; //Surcharge 20%
        taka = taka + surcharge;
    }
    else if(unit >=101 && unit <= 250)
    {
        //For next 100 units Tk. 3.00/unit
        taka = unit * 3.0;
        surcharge = taka * 0.2; //Surcharge 20%
        taka = taka + surcharge;
    }
    else if(unit >=251)
    {
        //For unit above 250 Tk. 3.75/unit
        taka = unit * 3.75;
        surcharge = taka * 0.2; //Surcharge 20%
        taka = taka + surcharge;
    }
    printf("\nTotal cost: %0.2f\n\n", taka);
    return 0;
}
Sample Output
Enter unit: 500

Total cost: 2250.00


Process returned 0 (0x0)   execution time : 3.293 s
Press any key to continue.
Change Theme
X