Tuesday, 17 January 2012

Write a program that will calculate and print bills for the city power company. The rates vary depending on whether the use is residential, commercial, or industrial. A code of R means residential use, a code of c means commercial use, and a code of I means industrial use


Write a program that will calculate and print bills for the city power company. The rates vary depending on whether the use is residential, commercial, or industrial. A code of R means residential use, a code of c means commercial use, and a code of I means industrial use. Any other code should be treated as error.

The rates are computed as follows:

R: $6.00Rs plus $0.052 per kwh used
C: $60.00 for the first 1000kwh and $0.045 for additional kwh.
I: Rate varies depending upon time of usage given below:
 
      Peak hours: $76.00 for first 1000 kwh and $0.065 for each
                                                             additional kwh.
      Off-peak hours: $40.00 for first 1000 kwh and $0.028 for each
                                                                     additional kwh.

Your program should prompt the use to enter his integer id, the use code (type char), and the necessary consumption figures in whole numbers of kilowatt-hours. Your program should display the amount due from the user.


#include<iostream>
#include<conio.h>
#include <iomanip>

using namespace std;

int main()
{
    int id, consumption;
    double bill;
    char code,ch;

    cout << "Enter your ID: ";
    cin >> id;

    cout << "\nEnter your Use Code (R/r, C/c or I/i): ";
    cin >> code;

    if(code=='r' || code=='R')
    {
        cout << "\nEnter your consumption figures in whole numbers of kwh: ";
        cin >> consumption;
        bill = consumption*(0.052 + 6.00);
    }

    else if(code=='c' || code=='C')
    {
        cout <<"\nEnter your consumption figures in whole numbers of kwh: ";
        cin >> consumption;

        if (consumption <= 1000 )
            bill = 60.00;
        else
            bill = (consumption-1000)*0.045 + 60.00;
    }

    else if(code=='i' || code=='I')
    {
        cout << "\n Enter P/p for Peak hours and O/o for off-peak hours consumptions: ";
        cin >> ch;

            if(ch=='O' || ch=='o')
            {
                cout << "\nEnter your off-peak hours consumption figures in whole numbers of kwh: ";
                cin >> consumption;

                if (consumption <= 1000)
                    bill = 40.00;

                else
                    bill = (consumption-1000)*0.028 + 40.00;
            }
            else if(ch=='P' || ch=='p')
            {
                cout << "\nEnter your peak hours consumption figures in whole numbers of kwh: ";
                cin >> consumption;

                if (consumption <= 1000)
                    bill = 76.00;

                else
                    bill = (consumption-1000)*0.065 + 76.00;
            }
            else
                    cout << endl << "Invalid Character\n\n";
    }
    else
        cout  << endl << "\n \t\tERROR in CODE \n";

    if(code=='r' || code=='R' || code=='c' || code=='C' || code=='i' || code=='I')
    {
    cout << "\nThe Amount Due is:\t" << fixed << setprecision(2) << (double)bill << " $\n";
    }
    getche();
    return 0;
}



2 comments: