Originally Posted by
laserlight
What exactly are you having difficulty with? If it is "everything", then start at the beginning and explain, for that one part of your task, what trouble you have with it.
Well i worked at it and it runs, but I don't know how to modify it to run with the functions that need to be applied. The Get_Data, Calaculate_Charge, and Print_Results.
Code:
#include<stdio.h>
#include<conio.h>
int charge(int power){
if(power <= 300) return power * 9;
else if(power > 300 && power <= 600) return 300 * 9 + (power - 300) * 8;
else if(power > 600 && power <= 1000) return 300 * 9 + 300 * 8 + (power - 600) * 6;
else if(power > 1000) return 300 * 9 + 300 * 8 + 400 * 6 + (power - 1000) * 5;
}
int main(){
int customernumber, kwh, count = 0, sum = 0;
float total = 0;
char more;
do{
count++;
printf("Enter customer number and kwh: ");
scanf("%d %d", &customernumber, &kwh);
sum += kwh;
printf("\nCustomer Num: %d\tKWH used: %d\tCharge: %.2f\n\n", customernumber, kwh, (float)(charge(kwh)) / 100);
printf("Do you have more data? (y/n)> ");
total += (float)(charge(kwh)) / 100;
more = getch();
printf("\n\n");
}while(more == 'y');
printf("\n===========================================================================\n\n");
printf("Total customers: %d\tTotal KWH used: %d\tTotal charges: %.2f", count, sum, total);
return 0;
}