Sathvikks8

Lab Program 4

Apr 10th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 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; //100 is the meter charges
  15.     }
  16.     else if(units>200 && units<=300)
  17.     {
  18.         excess=units-200;
  19.         total=(200*0.8)+(excess*0.9)+100; //100 is the meter charges
  20.     }
  21.     else if(units>300)
  22.     {
  23.         excess=units-300;
  24.         total=(200*0.8)+(100*0.9)+(excess*1)+100; //100 is the meter charges
  25.     }
  26.     else
  27.     {
  28.         printf("\nEnter valid units"); // Prints invalid if unit entered is negative
  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