Advertisement
conception

5

Feb 27th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /* Kariann Fenoglio
  2. CIS 236
  3. Assignment 5*/
  4.  
  5. #include<stdio.h>
  6. // Calculate_charge
  7. int charge(int power){
  8. if
  9. (power <= 300) return power * 9;
  10. else if
  11. (power > 300 && power <= 600) return 300 * 9 + (power - 300) * 8;
  12. else if
  13. (power > 600 && power <= 1000) return 300 * 9 + 300 * 8 + (power - 600) * 6;
  14. else if
  15. (power > 1000) return 300 * 9 + 300 * 8 + 400 * 6 + (power - 1000) * 5;
  16. }
  17. // Get_data
  18. int main(void){
  19. int custnum, kwh, count = 0, sum = 0;
  20. float total = 0;
  21. char more;
  22.  
  23. do{
  24. count++;
  25. printf("Enter customer number and kwh: ");
  26. scanf("%d %d", &custnum, &kwh);
  27. sum += kwh;
  28.  
  29. // Print_results
  30. printf("\nCustomer Num: %d\tKWH used: %d\tCharge: %.2f\n\n", custnum, kwh, (float)(charge(kwh)) / 100);
  31. printf("Do you have more data? (y/n)> ");
  32.  
  33. total += (float)(charge(kwh)) / 100;
  34. more = getch();
  35. printf("\n\n");
  36.  
  37. }
  38. while(more == 'y');
  39. printf("===========================================================================\n\n");
  40. printf("Total customers: %d\tTotal KWH used: %d\tTotal charges: %.2f", count, sum, total);
  41.  
  42. return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement