Calculate Electric Bill C Program

How to write a c program to calculate electric bill in c programming ?


Solution:
/* Line charge = 50 tk */
/* For first 100 units, 1 unit = 5 tk */
/* For next 400 units, 1 unit = 6.5 tk */
/* For usage above 500 units, 1 unit = 8 tk */

#include <stdio.h>

int main()
{
int unit;
double cost = 100;

printf("Enter the number of units used: ");
scanf("%d", &unit);

if(unit <= 100)
        cost = cost + unit * 5;
    else if(unit <= 500)
       cost = cost + 100*5 + (unit - 100) * 6.5;
    else
        cost = cost + 100*5 + 400*6.5 + (unit - 500) * 8;

    printf("Total cost = %lf\n", cost);

return 0;
}


Learn More :