Sunday, March 7, 2010

C++ PROGRAM TO CALCULATE THE ELECTRICITY BILL

main()
{
 char name[100],flag = 'y';
 int no_unit;
 double rs;
 float rate1=0,rate2=0,rate3=0;
 clrscr();
 while(flag == 'y' || flag == 'Y')
 {
  clrscr();
  cout<<"\n\t\t ********** C-PROGRAM FOR ELECTRICITY BILL **********";
  cout<<"\n ENTER THE NAME : ";
  cin>>name;
  cout<<"\n ENTER THE NUMBER OF UNITS : ";
  cin>>no_unit;
  if(no_unit>300)
  {
   for(int i=1;i<=100;i++)
   {
    rate1 = i * 0.60;
   }
   for(i=100;i<=300;i++)
   {
    rate2 = i * 0.80;
   }
   for(i=300;i<=no_unit;i++)
   {
    rate3 = i * 0.90;
   }
 }
 else if(no_unit<300 && no_unit>100)
 {
   for(int i=1;i<=100;i++)
   {
    rate1 = i * 0.60;
   }
   for(i=100;i<=no_unit;i++)
   {
    rate2 = i * 0.80;
   }
 }
 else if(no_unit<=100)
 {
  for(int i=1;i<=no_unit;i++)
  {
   rate1 = i * 0.60;
  }
 }
 double rate = rate1+rate2+rate3;
 if(rate<50)
 {
  rate = 50.00;
 }
 else if(rate>300)
 {
  float add = rate * 0.15;
  rate = rate+add;
 }
 clrscr();
 cout<<"\n\n\t THE USER NAME IS     : "<
 cout<<"\n\n\t NO.OF UNITS CONSUMED : "<
 cout<<"\n\n\t TOTAL BILL IS        : Rs."<<<" Ps";
 cout<<"\n\n FOR ANOTHER BILL PRESS Y or y : ";
 flag = getch();
}
 return 0;
}

2 comments:

  1. #include
    #include
    using namespace std;
    int main()
    {
    //clear the screen

    //declare uc variable as int
    int uc;
    //declare variables as float
    float amt, famt, tax;
    //Input the units consumed
    cout << "Enter the units consumed by the consumer" << endl;
    cin >> uc;
    //conditional statement
    if (uc >= 0 && uc <= 100)
    amt = uc * 1;
    else
    {
    if (uc>100 && uc <= 200)
    amt = ((uc - 100) * 2) + 100;
    else
    {
    if (uc>200 && uc <= 300)
    amt = ((uc - 200) * 3) + 300;
    else
    {
    if (uc>300 && uc <= 500)
    amt = ((uc - 300) * 4) + 600;
    else
    amt = ((uc - 500) * 5) + 1400;
    }
    }
    }
    //calculate tax and final amount
    tax = (amt * 10) / 100;
    famt = amt + 50 + tax;
    //print the bill
    cout << "---------------------------" << endl;
    cout << " Bill " << endl;
    cout << "---------------------------" << endl;
    cout << "Bill of units " << amt << endl;
    cout << "Meter charges 50" << endl;
    cout << "Tax " << tax << endl;
    cout << "---------------------------" << endl;
    cout << "Total bill " << famt << endl;
    cout << "---------------------------" << endl;

    return main();
    }

    ReplyDelete
  2. More easy program http://www.compprog.com/2013/04/write-program-for-electricity-bill.html

    ReplyDelete