Question: Code in C please (not C++) This program is to allow people to calculate their total and average electric bill over a period of several

Code in C please (not C++)

This program is to allow people to calculate their total and average electric bill over a period of several months. For each month they will enter their electric usage in kwh, and their bill will be calculated with the following formula:

bill = CONNECTION_CHARGE + kwh * 0.065

The CONNECTION_CHAGRE should be a defined constant of 17.00, and you should write a function that takes the kwh as its argument and returns the amount of the bill. (A double.) That months is then added to a sum.

At the beginning of the program the user is asked to enter a number that says how many months they will averaging, and there is also a counter that is initialized to zero. (The counter and the number of months will be integers they are counting something.) You will also need to set your sum (a double) to zero.

The loop runs while the counter is less than the number of months.

The final output is the total of all the electric bills for those months, and the average of those bills.

The program looks something like this:

  • Declare number-of-months, counter, kwh, bill (to store value returned from the function), sum, and average.
  • Initialize counter and sum to zero.
  • Ask the user how many months they will be calculating, and read it in
  • Start the loop that runs while the counter is less than the number of months
  • Inside the loop:
    • Ask the user for the kwh used
    • Call the function.
    • Add the result to the sum.
    • Add one to the counter.
  • After the loop:
    • Compute the average monthly bill
    • Output the sum and the average.

Here is a sample run:

For how many months will you be averaging your electric bill? 3

How many kilowatt hours were used in month 1 ? 120

How many kilowatt hours were used in month 2 ? 102

How many kilowatt hours were used in month 3 ? 88

Your total bills for 3 months was $310.00 and your average was $103.33

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!