Advertisement
Guest User

Untitled

a guest
May 31st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. /* Function Declarations */
  4. char getUserType();
  5. int getKwPerHour();
  6. float getPriceCharge(char, int);
  7. void displayAnalysis(int, float, int, float);
  8. char getVerification();
  9. /*********************/
  10.  
  11. void main() {
  12.     char verification;
  13.     char userType;
  14.     int kwPerHour;
  15.     float priceCharge;
  16.    
  17.     //local variables increments add for finalisation
  18.     int privateCustomers = 0;
  19.     float privateCustomersCost = 0.0;
  20.     int commercialCustomers = 0;
  21.     float commercialCustomersCost = 0.0;
  22.    
  23.     while (verification != 'N') {
  24.         userType = getUserType();
  25.         kwPerHour = getKwPerHour();
  26.         priceCharge = getPriceCharge(userType, kwPerHour);
  27.  
  28.         if (userType == 'P') {
  29.             privateCustomers++;
  30.             privateCustomersCost += priceCharge;
  31.         } else if (userType == 'C') {
  32.             commercialCustomers++;
  33.             commercialCustomersCost += priceCharge;
  34.         }
  35.        
  36.         verification = getVerification();
  37.         getchar();
  38.     }
  39.     displayAnalysis(privateCustomers, privateCustomersCost, commercialCustomers, commercialCustomersCost);
  40. }
  41.  
  42. char getUserType() {
  43.     char userType;
  44.     printf("\nEnter user type (P/C): P = Private, C = Commercial : \n");
  45.     scanf("%c", &userType);
  46.     return userType;
  47. }
  48.  
  49. int getKwPerHour() {
  50.     int kwPerHour;
  51.     printf ("Enter kilowatts used per hour:\n");
  52.     scanf ("%d", &kwPerHour);
  53.     return kwPerHour;
  54. }
  55.  
  56. float getPriceCharge(char userType, int kwPerHour) {
  57.     float excessCharge = 0.0;
  58.     float chargeMultiplier;
  59.     float priceCharge;
  60.    
  61.     if (userType == 'P') {
  62.         chargeMultiplier = 0.68;
  63.        
  64.         if (kwPerHour > 1000) {
  65.             excessCharge = -((kwPerHour - 1000)  * 0.68) * 0.005;
  66.         }
  67.        
  68.     } else if (userType == 'C') {
  69.         chargeMultiplier = 0.74;
  70.        
  71.         if (kwPerHour > 100000) {
  72.             excessCharge = ((kwPerHour - 100000)  * 0.74) * 0.01;
  73.         }
  74.        
  75.     }
  76.    
  77.     priceCharge = ((kwPerHour * chargeMultiplier) + excessCharge) + 50.0;
  78.     printf ("\nCharge = $%.2f \n ", priceCharge);
  79.    
  80.     return priceCharge;
  81. }
  82.  
  83. char getVerification() {
  84.     char verif;
  85.      
  86.     printf("\nWould you like to continue? Y = yes, N = no\n");
  87.     getchar();
  88.     scanf("%c", &verif);
  89.  
  90.     while(verif != 'N' && verif != 'Y') {
  91.        printf("%c is not a valid entry, please re-enter your choice.\n", verif);
  92.        getchar();
  93.        scanf("%c", &verif);
  94.     }
  95.  
  96.     return verif;
  97. }
  98.  
  99. void displayAnalysis(int pAmt, float pCost, int cAmt, float cCost) {
  100.    
  101.     printf ("\n Private users = %d \n ", pAmt);
  102.     printf ("Total amount received from private users = $%.2f \n ", pCost);
  103.     printf ("Average amount received from private users = $%.2f \n ", pCost / pAmt);   
  104.  
  105.     printf ("\n Commercial users = %d \n ", cAmt);
  106.     printf ("Total amount received from commercial users = $%.2f \n ", cCost);
  107.     printf ("Average amount received from commercial users = $%.2f \n ", cCost / cAmt);
  108.    
  109.     printf ("\n\nExiting program...\n");
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement