C program to reads customer number and power consumed and prints amount to be paid
An electric power distribution company charges its domestic consumers as follows
1 2 3 4 5 6 7 |
Consumption Rate of Units Charge ------------------------------------------------------ 0-200 Rs.0.50 per unit 201-400 Rs.100 plus Rs.0.65 per unit excess 200 401-600 Rs.230 plus Rs.0.80 per unit excess of 400. ------------------------------------------------------- |
Write a C program that reads the customer number and power consumed and prints the amount to be paid by the customer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> #include<conio.h> void main() { int cust_no, powerUsage; float amount; clrscr(); printf("Enter the customer number: "); scanf("%d", &cust_no); printf("Enter the power consumed: "); scanf("%d", &powerUsage); if (powerUsage >= 0 && powerUsage <= 200) amount = powerUsage * 0.50; else if (powerUsage > 200 && powerUsage < 400) amount = 100 + ((powerUsage - 200) * 0.65); else if (powerUsage > 400 && powerUsage <= 600) amount = 230 + ((powerUsage - 400) * 0.80); printf("Amount to be paid by customer no. %d is Rs.:%5.2f.", cust_no, amount); getch(); } |
Output :
1 2 3 |
Enter the customer number: 1 Enter the power consumed: 100 Amount to be paid by customer no. 1 is Rs.:50.00. |