Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Could someone please help me finish this C program? I'd really appreciate it, thanks. City calculates the monthly Electricity utility bill based on the number

Could someone please help me finish this C program? I'd really appreciate it, thanks.

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 Dominos 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. See 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 = 9image text in transcribedimage text in transcribedimage text in transcribed

1 #include-stdio.h> 2 #include-string.h> 3 #include-math.h> 4 5 void displayMenu (); 6 int errorCheck(int option); 7 int errorCheckUnits(int units); 8 float getRate(int units, int option); 9 int charge(int option); 10 12 int main (void) 13 f 14 15 16 17 18 19 20 21 int option; displayMenu); //Menu function call// while (1) printf( Choose a type of connection scanf(9sd, &option); if (errorCheck(option) ) 23 24 25 26 27 28 29 30 31 32 Invalid Choice! Please enter a vali printf( continue; else break; 34 35 36 37 38 39 40 41 return 43 44 void displayMenu() 45 t 46 47 48 49 50 51 52 int errorCheck( option) 53 f 54 nln) printf ( printf( olololokELECTRICITY BILL CALCULATOR '1.Residential Ini n2.Commercia n3.Industrial Intn) return (num> 11 num

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions