Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The local electricity company has three types of customers: Residential ( R ), C

ID: 670132 • Letter: T

Question

The local electricity company has three types of customers: Residential ( R ), Commercial ( C ), and Industrial ( I ). The electric bill depends on the type of customer and the amount of electricity used in kilowatts.

Write a program to ask the user for his type ( R, C, or I) and the amount used in kilowatts and then it prints out how much he should pay, given that the price per kilowatt is $0.01 for a Residential customer, $0.03 for a Commercial customer, and $0.05 for an Industrial customer.

Sample Run:

What type of Customer are you? (R, C, or I)     C

How many kilowatts did you use?   4000

Your bill is 120 dollars

Call your program Lastname_bill.py and submit it on Blackboard

Explanation / Answer

#include <stdio.h>


void main()
{
// commercial customer
const int COM_LIMIT = 1000;
const double COM_RATE = 0.045;
const double COM_FEE = 60;
// residential customer
const double RES_RATE = 6.052;
// industrial customer
const int IND_LIMIT = 1000;
const double IND_RATE_PEAK = .065;
const double IND_FEE_PEAK = 76;
const double IND_RATE_OFF = .028;
const double IND_FEE_OFF = 40;
int account, consumption=0, off_consumption=0, peak_consumption=0;
double bill=0.0;
char code;

printf("Please enter your account number: ");
scanf("%d", &account);

printf(" Please enter your use code (R, C or I): ");
scanf("%c", &code);

if (code=='r' || code=='R')
{
printf(" Please enter your consumption figures in whole numbers of kwh: ");
scanf("%d", &consumption);
bill = consumption*RES_RATE;
}

if (code=='c' || code=='C')
{
printf(" Please enter your consumption figures in whole numbers of kwh: ");
scanf("%d", &consumption);


if (consumption < COM_LIMIT)
bill = COM_FEE;


else
bill = (consumption*COM_RATE) + COM_FEE;
}

if (code=='i' || code=='I')
{
printf(" Please enter your off-peak consumption figures in whole numbers of kwh: ");
scanf("%d", &off_consumption);
if (off_consumption < IND_LIMIT)
bill = IND_FEE_OFF;


else if (off_consumption >= IND_LIMIT)
bill = (consumption*IND_RATE_PEAK) + IND_FEE_PEAK;

printf(" Please enter your peak consumption figures in whole numbers of kwh: ");
scanf("%d", &peak_consumption);
if (peak_consumption < IND_LIMIT)
bill = IND_FEE_PEAK;

else if (peak_consumption >= IND_LIMIT)
bill = consumption*IND_RATE_OFF + IND_FEE_OFF;
}



printf(" Account number: %d", account);
printf(" Code: %c", code);
printf(" Consumption: %d", consumption);
printf(" Bill: %.2f", bill);
}