In: Computer Science
US government website says the following interesting information: In 2017, the average annual electricity consumption for a U.S. residential utility customer was 10,399 kilowatthours (kWh), an average of 867 kWh per month. Louisiana had the highest annual electricity consumption at 14,242 kWh per residential customer, and Hawaii had the lowest at 6,074 kWh per residential customer.
Let us compute the electricity usage and the bill for last month by asking a few questions to a homeowner. Here are the input parameters and output format.
Input: # of light bulbs Average # of hours each bulb is ON in a day AC unit's power Typical # of hours AC unit is ON in a day # of FANs Average # of hours each Fan is ON in a day Per-unit price of electricity Formatted output: Total electricity usage: NNNN kWh Bulbs: XX.X% AC: YY.Y% FANs: ZZ.Z% Electricity bill for the month: $ NNNN.NN
Here is the sample input:
# of light bulbs: 10
Average # of hours each bulb is ON in a day: 2.4
AC unit's power: 900
Typical # of hours AC unit is ON in a day: 10.5
# of FANs: 4
Average # of hours each Fan is ON in a day: 8.5
Per-unit price of electricity: 9.5
Here is the corresponding output:
Total electricity usage: 368 kWh Bulbs: 11.8% AC: 77.1% FANs: 11.1% Electricity bill for the month: $ 34.91
Notes:
Help!
Code
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int numBulbs, numFans;
double avgBulbON, ACUnitPower, AC_ON_Hrs, avgFanON,
perUnitPrice;
double fanC, bulbC, AC_C, totalConsumption=0;
double fanPer,bulbPer,ACPer;
double totalPrice;
cout<<"# of light bulbs: ";
cin>>numBulbs;
cout<<"Average # of hours each bulb is ON in a
day: ";
cin>>avgBulbON;
cout<<"AC unit's power: ";
cin>>ACUnitPower;
cout<<"Typical # of hours AC unit is ON in a
day: ";
cin>>AC_ON_Hrs;
cout<<"# of FANs: ";
cin>>numFans;
cout<<"Average # of hours each Fan is ON in a
day: ";
cin>>avgFanON;
cout<<"Per-unit price of electricity: ";
cin>>perUnitPrice;
fanC=avgFanON*numFans*40;
bulbC=avgBulbON*numBulbs*60;
AC_C=AC_ON_Hrs*ACUnitPower;
totalConsumption=fanC+bulbC+AC_C;
fanPer=100*fanC/totalConsumption;
bulbPer=100*bulbC/totalConsumption;
ACPer=100*AC_C/totalConsumption;
totalConsumption=ceil((totalConsumption*30)/1000);
totalPrice=totalConsumption*perUnitPrice;
cout<<"\nTotal Total electricity usage:
"<<totalConsumption<<" kWh"<<endl;
cout<<fixed<<setprecision(1);
cout<<"Bulbs: "<<bulbPer<<"% AC:
"<<ACPer<<"% FANs: "<<fanPer<<"%\n";
cout<<fixed<<setprecision(2);
cout<<"Electricity bill for the month:
$"<<totalPrice/100<<endl;
return 1;
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.