Program to calculate electricity bill using ladder if-else

Write a program to generate an electricity bill using a ladder if-else.

Condition to calculate electricity bill: 
  1. Reading<=200 then a charge will be 500rs.
  2. 200<Reading<=400 then rates will be 3rs per reading.
  3. 400<Reading<=600 then rates will be 4rs per reading.
  4. Reading>600 then the rate will be 5rs per reading.

Approach

C Program

#include <stdio.h>
int main()
{
    int reading;
    printf("Enter reading of bill : ");
    scanf("%d", &reading);
    if (reading <= 200)
    {
        int amount = 500;
        printf("Charge for %d reading is %d\n"readingamount);
    }
    else if (reading > 200 && reading <= 400)
    {
        int amount = 3 * reading;
        printf("Charge for %d reading is %d\n"readingamount);
    }
    else if (reading > 400 && reading <= 600)
    {
        int amount = 4 * reading;
        printf("Charge for %d reading is %d\n"readingamount);
    }
    else if (reading > 600)
    {
        int amount = 5 * reading;
        printf("Charge for %d reading is %d\n"readingamount);
    }
    return 0;
}
Input:

Enter reading of bill : 230

Output:

Charge for 230 reading is 690


No comments:

Post a Comment