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 changed a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400, then an additional surcharge of 15% of total amount is charged. Write a program to read the name of the user, number of units consumed and print out the charges.

All QuestionsCategory: C LanguageAn 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 changed a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400, then an additional surcharge of 15% of total amount is charged. Write a program to read the name of the user, number of units consumed and print out the charges.
nikhil.d asked 3 years ago
2 Answers
Best Answer
Anonymous answered 3 years ago

Note: Change the double inverted comma ( \” ) in the code to avoid an error.

nikhil.d answered 3 years ago

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char name[10];
    int units;
    const int mincharge = 100;
    const double slab1 = 0.80;
    const double slab2 = 0.90;
    const double slab3 = 1.00;
    const double surcharge = 0.15;
    double billamt = 0.0;
    printf(“enter the name of consumer\n”);
    scanf(“%s”, &name);
    printf(“enter the number of units consumed\n”);
    scanf(“%d”, &units);
    billamt = billamt + mincharge;
    if (units <= 200)
    {
        billamt = billamt + (units * slab1);
    }
    else if (units > 200 && units <= 300)
    {
        billamt = billamt + ((200 * slab1) + (units – 200) * slab2);
    }
    else
    {
        billamt = billamt + (200 * slab1) + (100 * slab2) + ((units – 300) * slab3);
    }
    if (billamt > 400)
    {
        billamt = billamt + (billamt * surcharge);
    }
    printf(“consumer name=%s\n”, name);
    printf(“units consumed =%d\n”, units);
    printf(“billamount=%f rupees\n”, billamt);
}