Hey all, for my assignment, im suppost to do the following:

"The electric company charges according to the following rate schedule:

9 cents per kilowatt-hour (kwh) for the first 300 kwh

8 cents per kwh for the next 300 kwh (up to 600 kwh)

6 cents per kwh for the next 400 kwh (up to 1,000 kwh)

5 cents per kwh for all electricity used over 1,000 kwh.

Write a function to compute and return the total charge for each customer. Write a main function to call the charge calculation function using the following data:

Customer Number Kilowatt-hours used

123 725

205 115

464 600

596 327

601 915

613 1,011

722 47

The program should print a three-column chart listing the customer number, the kilowatt-hours used, and the charge for each customer. The program should also compute and print the number of customers, the total kilowatt-hours used, and the total charges."

It is suppose to look like this:

Now for my coding, everthing works great! The only problem I have is getting the file part into the program as intructed by the picture where it adds the total number of customers, kwh and charged. Im not exactly sure how to go about doing that and where to add it at.

My Code:

Code:

#include <stdio.h>
int main (void)
{
int custnum;
int kwh, copy;
double total=0.0;
double finaltotal=0.0;
while(1) {
printf("Enter customer number and kwh (-1 to quit):");
scanf("%d", &custnum);
if (custnum == -1)
break;
scanf("%d", &kwh);
(void) getchar();
copy = kwh;
if(kwh > 300) {
total += 300 * 0.09;
kwh -= 300;
}else{
total += kwh * 0.09;
kwh = 0;
}
if(kwh > 300) {
total += 300 * 0.08;
kwh -= 300;
}else {
total += kwh * 0.08;
kwh = 0;
}
if(kwh > 400) {
total += 400 * 0.06;
kwh -= 400;
}else {
total += kwh * 0.06;
kwh = 0;
}
if(kwh > 1000) {
total += 1000 * 0.05;
kwh -= 1000;
}else {
total += kwh * 0.05;
kwh -= 0;
}
finaltotal = total;
kwh = copy;
printf("\nCustomer Num: %d KWH used:%10.2d Charge:%10.2f\n",
custnum, kwh, finaltotal);
finaltotal = total = 0;
}
(void) getchar();
return 0;
}

Any help would really be great!

Thanks