The Restless Palms Apartment complex includes electricity in the monthly rent bi
ID: 3829826 • Letter: T
Question
The Restless Palms Apartment complex includes electricity in the monthly rent billed to customers. The individual meters are read and the results stored in an input file called usage.txt. This file contains the name of the tenant, (first, followed by last name), the apartment number as an integer and the usage in KW, also as an integer. You are required to create a program to automate the generation of the monthly bill for each of the tenants - that is the rent, plus the electricity. Your program should store the result in a text file called paymentdue.txt. Your payment file should have the name of each tenant (first then last), their apartment number and the amount due. The information for each tenant should be written on one line. When calculating the amount due: all tenants pay a flat rental rate of 1500.00 The payment for electricity is computed as follows: a. There is a basic $20.00 service charge b. Electricity is charged at 0.150 per KW for the first 1000 KW c. Additional usage is charged at 0.175/KW up to 2000 KW d. Usage in excess of 2000 KW is charged O.2KW When your program is run, its output should be displayed exactly as shown in the sample output provided below. Sample usaee.txt Joseph Blaton 453 2000 Antillia Lewis 1234 1500 Herman Charles 234 600 Sample paymentdue.txtExplanation / Answer
#include <stdio.h>
int main()
{
int KW;
float amt, total_amt, base_charge;
/*
* Read Kw consumed by tenant
*/
printf("Enter total KW consumed: ");
scanf("%d", &KW);
/*
* Calculate electricity bill according to given conditions
*/
if(KW <= 1000)
{
Amt = KW * 0.150;
}
else if(unit <= 2000)
{
Amt =150 + ((KW-1000)*0.175); (note:first 1000 kw amount ie..1000*0.150=150)
}
else
{
amt = 325 + ((KW-2000)*0.2); (note:150+(2000-1000)*0.175=325)
}
/*
* Calculate total electricity bill
* after adding base charge
*/
base_charge = amt + 20;
total_amt = amt + base_charge;
printf("Electricity Bill = USD. %.2f", total_amt);
return 0;
}
Note: %.2f is used to print fractional values only up to 2 decimal places. You can also use %f to print fractional values normally up to six decimal places.
thank you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.