Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C Program to calculate electricity charges
- #include<stdio.h>
- #include<stdlib.h>
- void main()
- {
- char name[50];
- float units, total, excess;
- printf("Enter the name of the consumer: ");
- gets(name);
- printf("\nEnter the units consumed: ");
- scanf("%f",&units);
- if(units>=0 && units<=200)
- {
- total=(units*0.8)+100; //100 is the meter charges
- }
- else if(units>200 && units<=300)
- {
- excess=units-200;
- total=(200*0.8)+(excess*0.9)+100; //100 is the meter charges
- }
- else if(units>300)
- {
- excess=units-300;
- total=(200*0.8)+(100*0.9)+(excess*1)+100; //100 is the meter charges
- }
- else
- {
- printf("\nEnter valid units"); // Prints invalid if unit entered is negative
- exit(0);
- }
- if(total>400)
- {
- total=total+(0.15*total);
- }
- printf("\nConsumer Name\tUnits Consumed\tTotal Amount\n%s\t%f\t%f",name,units,total);
- }
Add Comment
Please, Sign In to add comment