Question
Would anyone mind helping with this c program? City calculates the monthly Electricity utility bill based on the number of units consumed. It has divided
Would anyone mind helping with this c program?
City calculates the monthly Electricity utility bill based on the number of units consumed. It has divided the users into 3 categories, Residential, Commercial and Industrial. Based on the type of connection the rates vary. The bill depends on the number of units consumed, which is read in kWh (kilowatt-hour). The total bill consists of two parts. Part 1 is the Energy Charge, the table below shows the slab rates for consumption for each type of connection. Part 2 is the Customer Charge, the City charges a fixed amount every month of $25 for Residential connection, $90 for Commercial connection and $850 if it is an Industrial connection.
Example: If Domino's Pizza, which comes under Commercial Connection, consumed 700kWh during the last month, based on the table below their rate is 14c / kWh.
Energy Charge= units consumed*(rate/100)
Energy Charge= 700*.14= $98
Total Bill = Energy Charge + Customer Charge
Total Bill= 98+90= $188
Develop a program in C that will input units consumed for the previous month and will calculate and display bill for that particular connection as shown in the sample output below. To begin, read a connection type from the user 1 for Residential, 2 for Commercial and 3 for Industrial. Assume that the user can enter an invalid input multiple times, so, prompt an appropriate error message until a valid connection is chosen. This error check is shown in the sample output below. Next, read units consumed for that connection, again, perform an error check. A unit is invalid if it is negative (less than zero). Here, again assume that the user can provide an invalid input for units multiple times. Using the connection type, units consumed and the rate from the table below calculate the total bill for Electricity for the user (using the formula above). Make sure the program loops and asks if the user wants to continue to calculate another Bill. If the user hits 1 the calculator should start again for a new bill, if the user hits 0 the program should terminate by showing the proper output (It should show how many times the bill was calculated and what is the grand total of all the bills). Implement the bonus after this. Your results should match the sample output below. Use formatting to print the dollar amount correct to 2 decimal places only.
Residential |
|
| Commercial |
|
| Industrial |
|
|
Lower Bound | Upper Bound | Rate(in cents) per kWH | Lower Bound | Upper Bound | Rate(in cents) per kWH | Lower Bound | Upper Bound | Rate(in cents) Per kWH |
|
|
|
|
|
|
|
|
|
0 | 300 | 7.50 | 0 | 300 | 10.50 | 0 | 300 | 36.50 |
>300 | 750 | 10 | >300 | 750 | 14 | >300 | 750 | 40 |
>750 | 1500 | 13.50 | >750 | 1500 | 17.50 | >750 | 1500 | 45.50 |
>1500 | Above | 15 | >1500 | Above | 20 | >1500 | Above | 50 |
|
|
|
|
|
|
|
|
|
Functions to implement:
NOTE: Use of global variables will result in a 30-point deduction.
void displayMenu();
Prints the display options
int errorCheck(int option);
Error checking inputs for displayMenu(). Returns a 0 if invalid, and 1 is the input is valid.
int errorCheckUnits(int units);
Error checking for valid unit inputs. If unit input is less than 0, return 0. If valid, return 1.
float getRate(int units, int option);
Takes in the users units and menu option. Determines the rate (in cents) per kWH by looking at the given number of units. Returns the rate.
int charge(int option);
Takes in the users menu option. Based off the users option, determine the customers charge. Return the customers charge.
int main (void)
The main function will be doing all of the function calls.
Bonus: Take a positive number (N) as an input (perform error check), print the numbers and calculate the sum of all numbers from 0 to N, also sum of all even numbers and sum of all odd numbers from 0 to N. (use for-loop)
Eg: Number is 4
0 1 2 3 4
Sum of all numbers is 10
Sum of even numbers = 6
Sum of odd numbers = 4
Sample Output
Character in bold are inputs from the user
$ ./a.out
***** ELECTRICITY BILL CALCULATOR *****
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 0
Invalid Choice! Please enter a valid choice
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 4
Invalid Choice! Please enter a valid choice
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 1
Enter the number of units (in kWh): -111
Invalid input! Please enter a positive value: -10
Invalid input! Please enter a positive value: 300
Total energy charge for the customer is: $22.50
Total Bill due from this connection is: $47.50
Do you want to continue and calculate another bill? If Yes enter 1 else 0: 1
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 0
Invalid Choice! Please enter a valid choice
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 0
Invalid Choice! Please enter a valid choice
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 2
Enter the number of units (in kWh): -99
Enter the number of units (in kWh): -99
Invalid input! Please enter a positive value: 400
Total energy charge for the customer is: $56.00
Total Bill due from this connection is: $146.00
Do you want to continue and calculate another bill? If Yes enter 1 else 0: 1
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 0
Invalid Choice! Please enter a valid choice
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 3
Enter the number of units (in kWh): -1
Invalid input! Please enter a positive value: -500
Invalid input! Please enter a positive value: 700
Total energy charge for the customer is: $280.00
Total Bill due from this connection is: $1130.00
Do you want to continue and calculate another bill? If Yes enter 1 else 0: 1
1. Residential
2. Commercial
3. Industrial
Choose the type of connection: 2
Enter the number of units (in kWh): 300
Total energy charge for the customer is: $31.50
Total Bill due from this connection is: $121.50
Do you want to continue and calculate another bill? If Yes enter 1 else 0: 0
You calculated the bill 4 times and the total amount from all the bills due is $1445.00
EXITING ELECTRICITY BILL CALCULATOR
*** BONUS *** //PERFORM ERROR CHECK
Enter a number: 5
The numbers are: 0 1 2 3 4 5
The sum of all numbers from 0 to 5 is 15
Sum of Even numbers = 6
Sum of Odd numbers = 9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started