C++ program to calculate Cost of electricity bill with input of meter reading (logic explained)

Here is the C++ program to calculate Cost of electricity bill with input of meter reading.  It takes inputs of current and previous reading of meter and calculates the bill. You all should have in mind how it works exactly. Here is the algorithm.
Steps
User side:
1: User asked to enter the previous reading of meter
2: User asked to enter the current reading of meter 
3: User displayed the cost of the bill
Developer side
1: Declare variables that are going to be used in program.
2: Input the previous reading of meter from user.
3: Input the current reading of meter from user.
4: Calculate units. (the difference of current and previous readings)
5: If the units are less than 100 then calculate cost by multiplying units with 6 and there is no surcharge on it.
6: If the units are greater than one hundred  and less than three hundred then calculate cost by multiplying units with 7.5 and calculate surcharge using following formula surcharge=(10/100)*cost;. Total cost is cost plus surcharge  on it.
7: If the units are greater than three hundred   then calculate cost by multiplying units with 9 and calculate surcharge using following formula  surcharge=(20/100)*cost;Total cost is cost plus surcharge  on it.
8: Display the cost.
9: Program ends here.

Code:

#include<iostream>
using namespace std;
void main()
{      //variable declaration
       int unit,preading,creading;
       float surcharge;
       double cost;
       //input of variables
       cout<<"Enter preveious reading"<<endl;
       cin>>preading;
       cout<<"Enter current reading"<<endl;
       cin>>creading;
       unit=creading-preading;
       cout<<"Units="<<unit<<"units"<<endl;
       if(unit<=100)
              {
                     cost=unit*6;
              }
       else if(unit>=101&&unit<=300)
                     {
                           cost=unit*7.5;
                           surcharge=(10/100)*cost;
                           cost=cost+surcharge;
                     }
              else if(unit>300)
                           {
                                  cost=unit*9;
                                  surcharge=(20/100)*cost;
                                  cost=cost+surcharge;
                           }
                     cout<<"cost of electricity bill for FAST-NU Faisalabad="<<endl;
                     cout<<cost<<endl;

       system("pause");

}

Output:


Comments

  1. Switching to green energy is the perfect solution to decrease the power consumption from the power companies and create our own energy sources. High electricity bills used to be a problem for lots of people who are sticking or want to stick to low budget monthly. A power alternative can solve that issue and eliminate your consumption considerably. Source

    ReplyDelete
  2. Gas and Electricity Prices UK- You may have been looking how to reduce (saving money) on your monthly bills? If so, then look into a utility supplier comparison website. You will discover some of the cheapest gas and electricity prices in your area when using an Electricity Bill Calculator. Bonuses

    ReplyDelete
  3. FESCO stands for Faisalabad electric deliver company. FESCO affords energy to nearly 4.01 million clients. The envisioned usual population beneath the FESCO land is over 26 million.

    ReplyDelete
  4. Nowadays, you’ll play an entertainment that will remind you of Bomberman, and it’ll be without a doubt more fun in case there are two of you playing. Murder your enemies and make, past any question, they can’t hurt you. Put your bombs around the common item and win a couple of compensate things. Make beyond any doubt you missing some time as of late the bomb explodes also use caution of the traps your equal will set.

    ReplyDelete
  5. I perused the over article and I got a few information from your article. It's really incredible and valuable information
    for us.

    ReplyDelete
  6. Incredible!! exceptionally valuable data you shared with us. thank you for sharing.
    thank you nice article

    ReplyDelete
  7. I dont know if someone has already told you this, and even if they have I want to confirm what they probably have said before – you are simply beautiful.

    ReplyDelete

Post a Comment