Wednesday, 11 February 2015

u2p4

An electricity board charges the following rates to domestic users to discharge large consumption of energy.
For the first 100 units – 60 P per unit
For next 200 units - 80P per unit
Beyond 300 units - 90 P per Unit
All users are charged a minimum of Rs.50.00. If the total amount is more than Rs. 300.00 then an additional surcharge of 15% is added. Write a program to read the names of users and number of units consumed and print out the charges with names.


 #include<iostream.h>  
 #include<conio.h>  
 #include<stdlib.h>  
 void main()  
 {  
  clrscr();  
  int u;  
  cout<<"Enter Number of users : ";  
  cin>>u;  
  if(u==0)  
  {  
      cout<<"\n\n\n\n\t\tBYE THEN";  
      getch();  
      exit(0);  
  }  
  char name['u'][10];  
  float units['u'],min_amt=50,surcharge=15;  
  double total_amt['u'];  
  cout<<"\n----------------------------------\nEnter name of the user and units consumed for particular user.";  
  for(int i=0;i<u;i++)  
  {  
       cout<<"\n\nEnter name of user("<<i+1<<") : ";  
       cin>>name[i];  
       cout<<"\nEnter Units consumed by "<<name[i]<<" : ";  
       cin>>units[i];  
  }  
  for(int j=0;j<u;j++)  
  {  
  total_amt[j]=0;  
  if(units[j]<=100)  
  {  
       total_amt[j] = units[j]*60/100;  
       if (total_amt[j]<=min_amt)  
       {  
           total_amt[j]=50;  
       }    
  }  
  else if(units[j]<=300)  
  {  
       total_amt[j] = total_amt[j] + (100*60/100) + (units[j]-100)*80/100;  
       if(total_amt[j]>300)  
       {  
             total_amt[j] = total_amt[j] + (total_amt[j]*surcharge/100);  
       }  
  }  
  else if(units[j]>300)  
  {  
       total_amt[j] = total_amt[j] + (100*60/100) + (200*80/100) + ((units[j]-300)*90/100);  
       if(total_amt[j]>300)  
       {  
             total_amt[j] = total_amt[j] + (total_amt[j]*surcharge/100);  
       }  
  }  
  }  
  cout<<"\n-----------------\nTotal Chargable amount for each user is as below : ";  
  cout<<"\n-----------------\nName\tAmount\n-----------------";  
  for(int d=0;d<u;d++)  
  {  
  cout<<"\n"<<name[d]<<"\t"<<total_amt[d];  
  }  
  getch();  
 }  
OUTPUT


No comments:

Post a Comment