Code:// ------------------------------------------------------------------------------------------ // Includes // ------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> #include <string.h> // ------------------------------------------------------------------------------------------ // Constants // ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------ // Prototypes // ------------------------------------------------------------------------------------------ // Problem #1 void Problem1( ); void ProcessUser(); void GetNumberYearsEmployed(int* pintYearsEmployed); void GetAmountPreviousPurchase(double* psngAmountPreviousPurchase); void GetEmployeeStatus(char* pcharEmployeeStatus); void GetTodaysTotalPurchase(double* psngTodaysTotalPurchase); void GetAnotherEmployee(char AnotherEmployee[]); void CalculateDiscountPercentage(double* pdblDiscount, char* pcharEmployeeStatus, int* pintYearsEmployed); double TotalDiscountAllowed(double currentDiscount, double previousDiscount); double CalculateTotalWithDiscount(double* psngTodaysTotalPurchase, double applicableDiscount); double CalculatePreviousDiscount(double *pCurrentDiscountPercentage, double *psngAmountPreviousPurchase); // ------------------------------------------------------------------------------------------ // Name: main // Abstract: This is where the program starts // ------------------------------------------------------------------------------------------ int main() { ProcessUser(); //pause to hold the screen to allow user to see the output system("pause"); return 0; } //call values void ProcessUser() { double totalGrossPurchase = 0; double totalNetPurchase = 0; double *pCurrentDiscountPercentage = 0; int* pintYearsEmployed = 0; double *psngAmountPreviousPurchase = 0; char *pcharEmployeeStatus = 0; double *psngTodaysTotalPurchase = 0; int intCount = 0; //store user response to process another employee char AnotherEmployee[10]; do { GetNumberYearsEmployed(pintYearsEmployed); GetAmountPreviousPurchase(psngAmountPreviousPurchase); GetEmployeeStatus(pcharEmployeeStatus); GetTodaysTotalPurchase(psngTodaysTotalPurchase); //calculate YTD double sngYTDAmount = *psngTodaysTotalPurchase + *psngAmountPreviousPurchase; //Get Count intCount = intCount + 1; //get discount applicable for employee CalculateDiscountPercentage(pCurrentDiscountPercentage, pcharEmployeeStatus, pintYearsEmployed); double currentDiscount = (*pCurrentDiscountPercentage) * (*psngTodaysTotalPurchase); double previousDiscounts = CalculatePreviousDiscount(pCurrentDiscountPercentage, psngAmountPreviousPurchase); double applicableDiscount = TotalDiscountAllowed(currentDiscount, previousDiscounts); double netPurchase = CalculateTotalWithDiscount(psngTodaysTotalPurchase, applicableDiscount); //add sold amount total gross purchase totalGrossPurchase += *psngTodaysTotalPurchase; //add net purchase for current purchase to total purchase totalNetPurchase += netPurchase; printf("Employee %d Summary\n", intCount); printf("The YTD amount in dollars is %lf\n", sngYTDAmount); printf("The Total purchase today before discount is %lf\n", *psngTodaysTotalPurchase); printf("The employee discount this purchase is %lf\n", applicableDiscount); printf("The Total with discount is %lf\n", netPurchase); printf("\n"); GetAnotherEmployee(AnotherEmployee); } while (AnotherEmployee != 'no'); //Display all employee total printf("All Employee Summary\n"); printf("The total Gross is %lf\n", totalGrossPurchase); printf("The Total Net is %lf\n", totalNetPurchase); printf("\n"); printf("\n"); } double CalculatePreviousDiscount(double *pCurrentDiscountPercentage, double *psngAmountPreviousPurchase) { return (*pCurrentDiscountPercentage) * (*psngAmountPreviousPurchase); } //GET AND VALIDATE INPUTS //Get user response to process another employee void GetAnotherEmployee(char AnotherEmployee[]) { do { printf("Another employee? (yes or no):"); scanf_s("%s", AnotherEmployee); } while (AnotherEmployee != 'no' || AnotherEmployee != 'yes'); } //Get Number of years employed void GetNumberYearsEmployed(int* pintYearsEmployed) { do { printf("Enter a number of years employed: "); scanf_s(" %d", pintYearsEmployed); } while (*pintYearsEmployed < 1); } //Get amount of previous purchase amount void GetAmountPreviousPurchase(double* psngAmountPreviousPurchase) { do { printf("Enter total amount of previous purchases before discount: "); scanf_s(" %lf", psngAmountPreviousPurchase); } while (*psngAmountPreviousPurchase <= 0); } //Get employee status void GetEmployeeStatus(char* pcharEmployeeStatus) { do { printf("Enter status (e for employee/m for manager): "); scanf_s(" %c", pcharEmployeeStatus); } while (*pcharEmployeeStatus != 'e' && *pcharEmployeeStatus != 'm'); } //Get todays total purchase amount void GetTodaysTotalPurchase(double* psngTodaysTotalPurchase) { do { printf("Enter today's total purchase: "); scanf_s(" %lf", psngTodaysTotalPurchase); } while (*psngTodaysTotalPurchase <= 0); } //Calculate discount percentage void CalculateDiscountPercentage(double* pdblDiscount, char* pcharEmployeeStatus, int* pintYearsEmployed) { if (*pcharEmployeeStatus == 'm') { if (*pintYearsEmployed >= 1 && *pintYearsEmployed <= 3) { *pdblDiscount = 0.20; } else if (*pintYearsEmployed >= 4 && *pintYearsEmployed <= 6) { *pdblDiscount = 0.24; } else if (*pintYearsEmployed >= 7 && *pintYearsEmployed <= 10) { *pdblDiscount = 0.30; } else if (*pintYearsEmployed >= 11 && *pintYearsEmployed <= 15) { *pdblDiscount = 0.35; } else { *pdblDiscount = 0.40; } } else if (*pcharEmployeeStatus == 'e') { if (*pintYearsEmployed >= 1 && *pintYearsEmployed <= 3) { *pdblDiscount = 0.10; } else if (*pintYearsEmployed >= 4 && *pintYearsEmployed <= 6) { *pdblDiscount = 0.14; } else if (*pintYearsEmployed >= 7 && *pintYearsEmployed <= 10) { *pdblDiscount = 0.20; } else if (*pintYearsEmployed >= 11 && *pintYearsEmployed <= 15) { *pdblDiscount = 0.25; } else { *pdblDiscount = 0.30; } } } //Caculate total discount allowed double TotalDiscountAllowed(double currentDiscount, double previousDiscount) { if (previousDiscount >= 200) { return 0; } else if (currentDiscount + previousDiscount <= 200) { return currentDiscount; } else { //partial discount return (200 - previousDiscount); } } //calculate total with discount double CalculateTotalWithDiscount(double* psngTodaysTotalPurchase, double applicableDiscount) { double netPurchase = *psngTodaysTotalPurchase - applicableDiscount; return netPurchase; }