Question

US government website says the following interesting information: In 2017, the average annual electricity consumption for...

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:

  • Assume that each bulb consumes 60W and each fan consumes 40W.
  • Assume that the home has only one AC unit and all other appliances including cooking range use other energy sources, NOT electricity. AC unit power is specified in watts.
  • 1 kWh stands for 1000 Watt-hours and it is considered as 1 unit of Electricity and the per-unit price is specified in cents.
  • Assume that the last month had 30 days.

Code C++

#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 bill;

//Reading input from user
cout << "\n# 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;

//Processing output
bulbC = (numBulbs * avgBulbON * 60 * 30) / 1000;
fanC = (numFans * avgFanON * 40 * 30) / 1000;
AC_C = (900 * 10.5 * 30) / 1000;

//Calculating total consumption
totalConsumption = bulbC + fanC + AC_C;

//Calculating Bill
bill = totalConsumption * (perUnitPrice * 0.01);

cout << fixed << setprecision(0);
cout << "\n\nTotal electricity usage: " << totalConsumption << " kWh";
cout << fixed << setprecision(1);
cout << "\nBulbs: " << ((bulbC/totalConsumption)*100) << "% AC: " << ((AC_C/totalConsumption)*100) << "% FANs: " << ((fanC/totalConsumption)*100) << "% ";
cout << fixed << setprecision(2);
cout << "\nElectricity bill for the month: $ " << bill << "\n\n";

return 0;
}

I am using an online textbook software called zybooks and even though my code works on an IDE, the submission requirements are very strict.How can I change my code to meet the requirements?

This is what the grading output says.

1:Compare output

Input: 1 1

900 6.7

1 1

9.76

Your output: # 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:

Total electricity usage: 286 kWh

Bulbs: 0.6% AC: 99.0% FANs: 0.4% Electricity bill for the month: $ 27.96

Your output does not contain: Total electricity usage: 184 kWh

Bulbs: 1.0% AC: 98.4% FANs: 0.7%

Electricity bill for the month: $ 17.95

2:Compare output

Input: 1 1

1 1

7 12.5

  10.15

Your output: # 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:

Total electricity usage: 390 kWh

Bulbs: 0.5% AC: 72.6% FANs: 26.9%

Electricity bill for the month: $ 39.62

Your output does not contain: Total electricity usage: 107 kWh

Bulbs: 1.7% AC: 0.0% FANs: 98.3%

Electricity bill for the month: $ 10.84

3:Compare Output

Input:  10 7.5

1 1

1 1

7.5

Your output: # 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:

Total electricity usage: 420 kWh

Bulbs: 32.2% AC: 67.5% FANs: 0.3%

Electricity bill for the month: $ 31.48

Your output does not contain: Total electricity usage: 136 kWh

Bulbs: 99.1% AC: 0.0% FANs: 0.9%

Electricity bill for the month: $ 10.22

4:Compare Output is correct

Homework Answers

Answer #1

NOTE: In your code you've hard-coded the consumption of AC, this is what I think is creating problem in your further calculations and output.

// Code:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   // to get from user
   int numBulbs, numFans;
   double hrsBulbOn, hrsFanOn, unitAC, hrsACOn, unitPrice;
   // to be calculated by program
   double totalBulb, totalFan, totalAC, totalConsumption;
   double percentBulb, percentFan, percentAC;
   double billAmount;

   // Getting input
   cout << endl << "# of light bulbs: ";
   cin >> numBulbs;

   cout << "Average # of hours each bulb in ON in a day: ";
   cin >> hrsBulbOn;

   cout << "AC unit's power: ";
   cin >> unitAC;

   cout << "Typical # of hours AC unit is ON in a day: ";
   cin >> hrsACOn;

   cout << "# of Fans: ";
   cin >> numFans;

   cout << "Average # of hours each Fan is ON in a day: ";
   cin >> hrsFanOn;

   cout << "Per-unit price of electricity: ";
   cin >> unitPrice;

   // Processing
   totalBulb = (numBulbs*hrsBulbOn*60*30)/1000.0;
   totalFan = (numFans*hrsFanOn*40*30)/1000.0;
   totalAC = (hrsACOn*unitAC*30)/1000.0;

   totalConsumption = totalBulb + totalFan + totalAC;

   percentBulb = (totalBulb/totalConsumption)*100.0;
   percentFan = (totalFan/totalConsumption)*100.0;
   percentAC = (totalAC/totalConsumption)*100.0;

   billAmount = totalConsumption*(unitPrice*0.01);

   // display output
   cout << fixed << setprecision(0);
   cout << endl << endl << "Total electricity usage: " << totalConsumption << " kWh" << endl;
   cout << fixed << setprecision(1);
   cout << "Bulbs: " << percentBulb << "% AC: " << percentAC << "% Fans: " << percentFan << "%" << endl;
   cout << fixed << setprecision(2);
   cout << "Electricity bill for the month: $ " << billAmount << endl;

   return 0;
}

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions