A coffee shop sells coffee beans at $10.50 per pound plus the cost of shipping.
ID: 3810326 • Letter: A
Question
A coffee shop sells coffee beans at $10.50 per pound plus the cost of shipping. Each order ships for $0.86 per pound plus a flat fee of $1.50 to cover overhead. Write a script that calculates the cost of an order. Your script must have: Help comments, including The name of the script A description of the script's functionality Any inputs that must exist for the script to execute correctly Any output variables, namely those variables that will be updated or created by the script The ENGR 111/112 MATLAB script standard header Appropriately-named variables CONSTANTS_IN_ALL_CAPITALS variables InCamelCase At least 6 lines of code. It is possible to do this in one line. That is bad style. Don't do bad style. Remember CIPO: Constants, Inputs, Processing, OutputsExplanation / Answer
% Constants
global COFFEE_BEAN_PRICE_PER_POUND = 10.50;
global SHIPPING_PRICE_PER_POUND = 0.86;
global FLAT_FEE = 1.50;
% calculates total cost of the order
function totalPrice = calculateOrderCost(noOfPounds)
global COFFEE_BEAN_PRICE_PER_POUND;
global SHIPPING_PRICE_PER_POUND;
global FLAT_FEE;
totalPrice = noOfPounds * (COFFEE_BEAN_PRICE_PER_POUND + SHIPPING_PRICE_PER_POUND);
totalPrice = totalPrice + FLAT_FEE;
end
% Testing
quantityInPounds = input("Enter Quantity :");
totalPrice = calculateOrderCost(quantityInPounds);
printf("Total cost for %d pounds is %f ", quantityInPounds, totalPrice);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.