Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- /* Function Declarations */
- char getUserType();
- int getKwPerHour();
- float getPriceCharge(char, int);
- void displayAnalysis(int, float, int, float);
- char getVerification();
- /*********************/
- void main() {
- char verification;
- char userType;
- int kwPerHour;
- float priceCharge;
- //local variables increments add for finalisation
- int privateCustomers = 0;
- float privateCustomersCost = 0.0;
- int commercialCustomers = 0;
- float commercialCustomersCost = 0.0;
- while (verification != 'N') {
- userType = getUserType();
- kwPerHour = getKwPerHour();
- priceCharge = getPriceCharge(userType, kwPerHour);
- if (userType == 'P') {
- privateCustomers++;
- privateCustomersCost += priceCharge;
- } else if (userType == 'C') {
- commercialCustomers++;
- commercialCustomersCost += priceCharge;
- }
- verification = getVerification();
- getchar();
- }
- displayAnalysis(privateCustomers, privateCustomersCost, commercialCustomers, commercialCustomersCost);
- }
- char getUserType() {
- char userType;
- printf("\nEnter user type (P/C): P = Private, C = Commercial : \n");
- scanf("%c", &userType);
- return userType;
- }
- int getKwPerHour() {
- int kwPerHour;
- printf ("Enter kilowatts used per hour:\n");
- scanf ("%d", &kwPerHour);
- return kwPerHour;
- }
- float getPriceCharge(char userType, int kwPerHour) {
- float excessCharge = 0.0;
- float chargeMultiplier;
- float priceCharge;
- if (userType == 'P') {
- chargeMultiplier = 0.68;
- if (kwPerHour > 1000) {
- excessCharge = -((kwPerHour - 1000) * 0.68) * 0.005;
- }
- } else if (userType == 'C') {
- chargeMultiplier = 0.74;
- if (kwPerHour > 100000) {
- excessCharge = ((kwPerHour - 100000) * 0.74) * 0.01;
- }
- }
- priceCharge = ((kwPerHour * chargeMultiplier) + excessCharge) + 50.0;
- printf ("\nCharge = $%.2f \n ", priceCharge);
- return priceCharge;
- }
- char getVerification() {
- char verif;
- printf("\nWould you like to continue? Y = yes, N = no\n");
- getchar();
- scanf("%c", &verif);
- while(verif != 'N' && verif != 'Y') {
- printf("%c is not a valid entry, please re-enter your choice.\n", verif);
- getchar();
- scanf("%c", &verif);
- }
- return verif;
- }
- void displayAnalysis(int pAmt, float pCost, int cAmt, float cCost) {
- printf ("\n Private users = %d \n ", pAmt);
- printf ("Total amount received from private users = $%.2f \n ", pCost);
- printf ("Average amount received from private users = $%.2f \n ", pCost / pAmt);
- printf ("\n Commercial users = %d \n ", cAmt);
- printf ("Total amount received from commercial users = $%.2f \n ", cCost);
- printf ("Average amount received from commercial users = $%.2f \n ", cCost / cAmt);
- printf ("\n\nExiting program...\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement