|
| 1 | +# Miscellaneous |
| 2 | + |
| 3 | +[](https://github.com/ComputeNepal/learn-c-programming "Go to GitHub repo") |
| 4 | +[](https://github.com/ComputeNepal/learn-c-programming) |
| 5 | +[](https://github.com/ComputeNepal/learn-c-programming) |
| 6 | + |
| 7 | +[](#license) |
| 8 | +[](https://github.com/ComputeNepal/learn-c-programming/issues) |
| 9 | + |
| 10 | +[](/CONTRIBUTING.md "Go to contributions doc") |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## 1. WAP to build a simple electricity bill generator. |
| 15 | + |
| 16 | +### Program |
| 17 | +```c |
| 18 | +//A simple program of electricity bill generator |
| 19 | + |
| 20 | +#include<stdio.h> |
| 21 | +#include <stdlib.h> |
| 22 | + |
| 23 | +int main(){ |
| 24 | + int units; |
| 25 | + float price; |
| 26 | + |
| 27 | + printf("Enter the units:\t"); |
| 28 | + scanf("%d",&units); |
| 29 | + system("clear"); |
| 30 | + |
| 31 | + if(units<=20){ |
| 32 | + price=units*4; |
| 33 | + } |
| 34 | + else if(units<=50){ |
| 35 | + price=(20*4)+((units-20)*7.3); |
| 36 | + } |
| 37 | + |
| 38 | + else if(units<=150){ |
| 39 | + price=((20*4)+(50*7.3))+((units-50)*8.6); |
| 40 | + } |
| 41 | + else if(units<=250){ |
| 42 | + price=(20*4+30*7.3+100*8.6)+((units-150)*9.5); |
| 43 | + } |
| 44 | + else if(units>250){ |
| 45 | + price=(20*4+30*7.3+100*8.6+100*9.5)+((units-250)*12.5); |
| 46 | + } |
| 47 | + |
| 48 | + //you can automate the bill no, date and sc no for advancement |
| 49 | + printf("~~~NEPAL ELECTRICITY AUTHORITY~~~\n"); |
| 50 | + printf("-----------------------------------\n"); |
| 51 | + printf("\tELECTRICITY BILL\n"); |
| 52 | + printf("-----------------------------------\n\n"); |
| 53 | + printf("BILL NO:\t843948394\n"); |
| 54 | + printf("BILL DATE:\t2079/12/12\n"); |
| 55 | + printf("BRANCH:\t\tDAMAK\n"); |
| 56 | + printf("-----------------------------------\n"); |
| 57 | + printf("SC NO:\t\t309.11.012A\n"); |
| 58 | + printf("BILL NO:\t843948394\n"); |
| 59 | + printf("TOTAL UNITS:\t%d\n",units); |
| 60 | + printf("TOTAL AMOUNT:\tRS.%.3f\n",price); |
| 61 | + printf("-----------------------------------\n"); |
| 62 | + printf("-----------------------------------\n"); |
| 63 | + return 0; |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +This C program allows a user to input total electricity units and generate |
| 68 | +the bill in proper format. |
| 69 | + |
| 70 | +The basic logic of this C program is to take an integer 'units' as input |
| 71 | +from the user and the if else ladder checks suitable case for the units. |
| 72 | +If the unit is less than or equals to 20 units, then the rate is Rs.4 per |
| 73 | +unit which is assigned to 'price'. But if the units exceeds 20 and less |
| 74 | +than or equals to 50 then the price of 20 units is added to the price of |
| 75 | +remaining units. Same case continues untill 250 units. If the unit is more |
| 76 | +than 250 then the total sum price of 250 units is added to price of remaining |
| 77 | +units. After 250 units the rate is Rs.12.5 per unit even if the unit is way |
| 78 | +heigher. |
| 79 | + |
| 80 | +Finally the bill is generated through a self written format which includes |
| 81 | +Bill no, Bill date, Total units, Total amount,etc. |
| 82 | + |
| 83 | +For example, if the user input is 40 then the bill is generated for 40 units. |
| 84 | + |
| 85 | +_output_ |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
0 commit comments