Convert the following pseudocode algorithm into a complete C++ program using a C
ID: 3858619 • Letter: C
Question
Convert the following pseudocode algorithm into a complete C++ program using a C++ compiler of your choice. When the program is completed, copy and paste the code into your word document and paste a screenshot of the output window below your code. Write an algorithm that is given your electric meter readings (in kilowatt-hours) at the beginning and end of each month of the year. The algorithm determines your annual cost of electricity on the basis of a charge of 6 cents per kilowatt-hour or the first 1000 kilowatt-hours of each month and 8 cents per kilowatt-hour beyond 1000. After printing out your total annual charge, the algorithm will determine if you have been energy conscious by displaying an appropriate message if you have used less than 10000 kilowatt-hours for the entire year. Solution: Set annualKwh to zero Set annualChg to zero Set month to 1 Get kwhBegin while monthExplanation / Answer
int main()
{
int kwhBegin,kwhEnd,kwhUsed;
double monthlyChg;
int annualKwh = 0;
double annualChg = 0;
int month = 1;
cout<<" Enter Begin reading : ";
cin>>kwhBegin;
while(month < 13) //generate monthly charge
{
cout<<" Enter End reading : ";
cin>>kwhEnd;
kwhUsed = kwhEnd - kwhBegin;
if(kwhUsed < 1000)
monthlyChg = .06 * kwhUsed;
else
monthlyChg = .06 * 1000 + (kwhUsed - 1000)* .08;
cout<<" Kilowatts used for the month of "<<month<<" is "<<kwhUsed;
cout<<" Your bill for the month is "<<monthlyChg;
annualKwh = annualKwh + kwhUsed;
annualChg = annualChg + monthlyChg;
kwhBegin = kwhEnd;
month = month +1;
}
cout<<" Your annual elecricity usage is "<<annualKwh<<" kilowatts.";
if(annualKwh < 10000)
cout<<" Thank you for conserving energy.";
return 0;
}
Output:
Enter Begin reading : 3456
Enter End reading : 4566
Kilowatts used for the month of 1 is 1110
Your bill for the month is 68.8
Enter End reading : 5999
Kilowatts used for the month of 2 is 1433
Your bill for the month is 94.64
Enter End reading : 7890
Kilowatts used for the month of 3 is 1891
Your bill for the month is 131.28
Enter End reading : 8777
Kilowatts used for the month of 4 is 887
Your bill for the month is 53.22
Enter End reading : 9821
Kilowatts used for the month of 5 is 1044
Your bill for the month is 63.52
Enter End reading : 10657
Kilowatts used for the month of 6 is 836
Your bill for the month is 50.16
Enter End reading : 12999
Kilowatts used for the month of 7 is 2342
Your bill for the month is 167.36
Enter End reading : 13875
Kilowatts used for the month of 8 is 876
Your bill for the month is 52.56
Enter End reading : 14555
Kilowatts used for the month of 9 is 680
Your bill for the month is 40.8
Enter End reading : 15666
Kilowatts used for the month of 10 is 1111
Your bill for the month is 68.88
Enter End reading : 16777
Kilowatts used for the month of 11 is 1111
Your bill for the month is 68.88
Enter End reading : 17800
Kilowatts used for the month of 12 is 1023
Your bill for the month is 61.84
Your annual elecricity usage is 14344 kilowatts.