Write a program to generate an electricity bill using a ladder if-else.
Condition to calculate electricity bill:
- Reading<=200 then a charge will be 500rs.
- 200<Reading<=400 then rates will be 3rs per reading.
- 400<Reading<=600 then rates will be 4rs per reading.
- 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", reading, amount);}else if (reading > 200 && reading <= 400){int amount = 3 * reading;printf("Charge for %d reading is %d\n", reading, amount);}else if (reading > 400 && reading <= 600){int amount = 4 * reading;printf("Charge for %d reading is %d\n", reading, amount);}else if (reading > 600){int amount = 5 * reading;printf("Charge for %d reading is %d\n", reading, amount);}return 0;}
Input:
Enter reading of bill : 230
Output:
Charge for 230 reading is 690
No comments:
Post a Comment