Sathvikks8

Program 4-SKS

Apr 11th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //C Program to calculate electricity charges
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. void main()
  5. {
  6. char name[50];
  7. float units, total, excess;
  8. printf("Enter the name of the consumer: ");
  9. gets(name);
  10. printf("\nEnter the units consumed: ");
  11. scanf("%f",&units);
  12. if(units>=0 && units<=200)
  13. {
  14. total=(units*0.8)+100;
  15. }
  16. else if(units>200 && units<=300)
  17. {
  18. excess=units-200;
  19. total=(200*0.8)+(excess*0.9)+100;
  20. }
  21. else if(units>300)
  22. {
  23. excess=units-300;
  24. total=(200*0.8)+(100*0.9)+(excess*1)+100;
  25. }
  26. else
  27. {
  28. printf("\nEnter valid units");
  29. exit(0);
  30. }
  31. if(total>400)
  32. {
  33. total=total+(0.15*total);
  34. }
  35. printf("\nConsumer Name\tUnits Consumed\tTotal Amount\n%s\t%f\t%f",name,units,total);
  36. }
Add Comment
Please, Sign In to add comment