Prompt
The discount method implemented in Q.2.2 is not sustainable. Mr. Gucci has
decided to rather offer the following discounts on a long‐term basis.
Amount Spend Percentage Discount
0 – R1000 10%
R1001 – R3000 30%
R3001 or more 35%
Write the pseudocode snippet that will represent the section of Mr. Gucci’s
application that allows a cashier at the shop to determine the amount of discount
to be awarded to a customer based on the total amount payable by the customer.
The cashier will enter the amount payable and then the discount will be calculated
and displayed. You also need to display the percentage discount awarded. NB: You
need to make use of parallel arrays as part of your answe.
Answer
Problem Analysis
- Mr. Gucci wants to implement a sustainable discount method based on the amount spent by customers.
- The discounts are defined based on different spending ranges: 10% for 0 to R1000, 30% for R1001 to R3000, and 35% for R3001 or more.
- The application needs to calculate and display the discount amount and percentage based on the amount payable by the customer.
- Parallel arrays will be used to store the spending ranges and corresponding percentage discounts.
Strategic Solution Development
- Define two parallel arrays:
spendRanges
to store the spending ranges anddiscountPercentages
to store the corresponding discount percentages. - Implement a function in the application that takes the amount payable as input and calculates the discount based on the spending ranges defined.
- Loop through the
spendRanges
array to determine the appropriate discount percentage based on the amount payable. - Calculate the discount amount using the determined percentage.
- Display the calculated discount amount and the corresponding percentage to the cashier.
Code-Based Solutions (Pseudocode)
The following pseudocode snippet represents the described logic:
// Define parallel arrays for spending ranges and corresponding discount percentages
spendRanges = [0, 1000, 3000]
discountPercentages = [10, 30, 35]
function calculateDiscount(amountPayable):
discount = 0
discountPercentage = 0
// Determine the discount percentage based on the amount payable
for i from 0 to length(spendRanges) - 1:
if amountPayable <= spendRanges[i]:
discountPercentage = discountPercentages[i]
break
// Calculate the discount amount
discount = (amountPayable * discountPercentage) / 100
// Display the discount amount and percentage
display "Discount amount: " + discount
display "Discount percentage: " + discountPercentage
// Prompt the cashier to enter the amount payable
input amountPayable
calculateDiscount(amountPayable)
Detailed Explanation
- In this pseudocode snippet,
spendRanges
anddiscountPercentages
arrays are defined to store the spending ranges and corresponding discount percentages. - The
calculateDiscount
function calculates the discount amount and percentage based on the amount payable by the customer. - It iterates through the
spendRanges
array to find the right discount percentage based on the amount payable entered by the cashier. - The discount amount is calculated using the determined discount percentage and displayed along with the percentage to the cashier.
By implementing this pseudocode snippet, Mr. Gucci's application can efficiently determine the discount to be awarded to customers based on their total amount payable, ensuring a sustainable discount method.
Description
Application to calculate discounts based on customer spending ranges. Provides accurate discount amount and percentage for better customer experience.
More Tools Advisors
Power BI Tools AdvisorAirflow Tools AdvisorAlteryx Tools AdvisorAmazon Redshift Tools AdvisorApache Hadoop Tools AdvisorApache Kafka Tools AdvisorD3.js Tools AdvisorDataRobot Tools AdvisorDocker Tools AdvisorGit Tools AdvisorGoogle Analytics Tools AdvisorGoogle BigQuery Tools AdvisorIBM Watson Tools AdvisorKNIME Tools AdvisorMATLAB Tools AdvisorMicrosoft Azure Data Services Tools AdvisorMongoDB Tools AdvisorOracle Data Analytics Tools AdvisorQlikView & QlikSense Tools AdvisorRapidMiner Tools AdvisorSAS Tools AdvisorStitch Tools AdvisorTIBCO Spotfire Tools AdvisorIBM planning analytics Tools AdvisorPowerShell Tools AdvisorPython Tools AdvisorChatGPT Tools AdvisorExcel Tools AdvisorSQL Tools AdvisorPower Apps Tools AdvisorPower Automate Tools AdvisorR Tools AdvisorSharePoint Tools AdvisorMicrosoft Fabric Tools AdvisorLangchain Tools AdvisorDBT Tools AdvisorLooker Tools AdvisorSnowflake Tools AdvisorTableau Tools AdvisorGitHub Tools AdvisorZapier Tools AdvisorOther Tools Tools Advisor