Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Kariann Fenoglio
- CIS 236
- Assignment 5*/
- #include<stdio.h>
- // Calculate_charge
- 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;
- }
- // Get_data
- int main(void){
- int custnum, kwh, count = 0, sum = 0;
- float total = 0;
- char more;
- do{
- count++;
- printf("Enter customer number and kwh: ");
- scanf("%d %d", &custnum, &kwh);
- sum += kwh;
- // Print_results
- printf("\nCustomer Num: %d\tKWH used: %d\tCharge: %.2f\n\n", custnum, 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");
- printf("Total customers: %d\tTotal KWH used: %d\tTotal charges: %.2f", count, sum, total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement