Question

USING MATLAB: Many organizations sell candy for fundraisers. Often the items are purchased in bulk to...

USING MATLAB:

Many organizations sell candy for fundraisers. Often the items are purchased in bulk to cut cost and suppliers offer quantity discounts.

1-5 bars = $ 0.75 each

6-10 bars = cost of 5 bars + $0.50 each additional

11-15 bars = cost of 10 bars + $0.40 each additional

More than 15 bars = cost of 15 bars + $0.30 each additional

Starting with the function

n = input('How many candy bars would you like to buy? ')

Create a program to prompt the user to enter the number of candy bars he or she would like to buy

and calculate the cost.

• Using if/else statements, calculate the cost of the total order ($) and the unit cost ($/bar) for any

value of n.

• Use the disp(‘ ‘) function to output the cost of the total order ($) and the unit cost ($/bar) for

any value of n

• If negative numbers are entered an error message should be displayed

Hint: num2str() and str2num()

extra credit:

Add strings together ['statement A' 'statementB'] = 'statement AstatementB'

The supplier offers a discount of 10% to repeat customers who purchase more than 15 bars.

• Use an additional input statement to determine if someone is a repeat customer

•   Use & or |logical operators to modify your program calculate the cost of the total order ($) and the unit cost ($/bar) for any value of n and repeat customer status.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer for your question in MATLAB Programming Language.

CODE :

%% Required variables
i = 1;
repeat = 0;
choice = " ";

%% Loop to repeat until user says No "N"
while(choice != "N")

disp("-------------------------------");
fprintf(" Customer No. %d\n",(i));
disp("-------------------------------\n");

%% Read number of candy bars from customer
n = str2num(input('How many candy bars would you like to buy? ', 's'));

%% Validates value n
while(n<=0)
disp("\nPlease enter value greater than 0 \n");
n = str2num(input('How many candy bars would you like to buy? ', 's'));
end

%% Calculates cost for 5, 10, 15 bars
fivebars = 5*0.75;
tenbars = fivebars + 5*0.50;
fifteenbars = tenbars + 5*0.40;
totalCost = 0;
unitCost = 0;

%% Keeps track of repeated customer's count
if(n>15)
repeat = repeat + 1;
end

%% Calculates total order cost based on n value
if (n>=1 && n<=5)
if(n==5)
totalCost = fivebars;
else
totalCost = n*0.75;
end
elseif (n>=6 && n<=10)
if(n == 10)
totalCost = tenbars;
else
totalCost = fivebars + (n-5)*0.50;
end
elseif (n>=11 && n<=15)
if(n == 15)
totalCost = fifteenbars;
else
totalCost = tenbars + (n-10)*0.40;
end
elseif (n>15)
totalCost = fifteenbars + (n-15)*0.30;
if (repeat > 1)
disp("\nRepeated Customer...Thank you :)\nWe Offer you discount of 10%\n\n");
totalCost = totalCost - (totalCost*0.1);
end
end

%% Calculates unit cost
unitCost = totalCost/n;

%% Displays output
fprintf("\nCost of total order : $ %.2f",totalCost);
fprintf("\nUnit Cost of each bar : $ %.2f\n\n",unitCost);
choice = input('Another customer [Y/N]? ','s');
while((strcmp(choice,"N")!=1) && (strcmp(choice,"n")!=1) && ((strcmp(choice,"Y")!=1) && (strcmp(choice,"y")!=1)))
disp("\nPlease enter valid choice..");
choice = input('Another customer [Y/N]? ','s');
end

%% Increment i value by 1
i = i+1;
end

SCREENSHOTS :

Please see the screenshots of the code below for indentations of the code .

1 2 3 4 %% Required variables i = 1; repeat = 0; choice = ; 6 %% Loop to repeat until user says No N 7 while(choice != N35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 if (n>=1 && n<=5) if(n=while((strcmp(choice, N)!=1) && (strcmp(choice, n)!=1) && ((strcmp(choice, Y) !=1) && (strcmp(choice,y) !=1))) disp(

OUTPUT :

Result executed in 21.469 sec(s) Customer No. 1 How many candy bars would you like to buy? 5 Cost of total order : $ 3.75 UniResult executed in 14.938 sec(s) Customer No. 1 How many candy bars would you like to buy? 18 Cost of total order : $ 9.15 UnResult executed in 15.958 sec(s) Customer No. 1 How many candy bars would you like to buy? -10 Please enter value greater tha

Any doubts regarding this can be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
USING MATLAB: Many organizations sell candy for fundraisers. Often the items are purchased in bulk to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...

    Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules: All units up to...

  • Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...

    Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while loop  Writing a for loop  Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...

  • NEED HELP WITH ALL PARTS 1-3 ebook Calculator Nonuniform Inputs Apeto Company produces premium chocolate candy...

    NEED HELP WITH ALL PARTS 1-3 ebook Calculator Nonuniform Inputs Apeto Company produces premium chocolate candy bars. Conversion costs are added uniformly. For February, EWIP is 40 percent complete with respect to conversion costs. Materials are added at the beginning of the process. The following information is provided for February Physical flow schedule Units to account for: Units in WWTP Units started 70,000 Tetal units to account for 70,000 Units accounted for Units completed From BWP 0 Started and completed...

  • Cane Company manufactures two products called Alpha and Beta that sell for $170 and $130, respectively....

    Cane Company manufactures two products called Alpha and Beta that sell for $170 and $130, respectively. Each product uses only one type of raw material that costs $6 per pound. The company has the capacity to annually produce 116,000 units of each product. Its average cost per unit for each product at this level of activity are given below: Alpha Beta Direct materials $ 30 $ 18 Direct labor 30 25 Variable manufacturing overhead 20 15 Traceable fixed manufacturing overhead...

  • 4. Assume that Cane expects to produce and sell 100,000 Betas during the current year. One...

    4. Assume that Cane expects to produce and sell 100,000 Betas during the current year. One of Cane’s sales representatives has found a new customer who is willing to buy 3,000 additional Betas for a price of $49 per unit. What is the financial advantage (disadvantage) of accepting the new customer's order? Return to question Cane Company manufactures two products called Alpha and Beta that sell for $170 and $130, respectively. Each product uses only one type of raw material...

  • Cane Company manufactures two products called Alpha and Beta that sell for $120 and $80, respectively....

    Cane Company manufactures two products called Alpha and Beta that sell for $120 and $80, respectively. Each product uses only one type of raw material that costs $6 per pound. The company has the capacity to annually produce 100,000 units of each product. Its average cost per unit for each product at this level of activity are given below: Alpha Beta Direct materials $ 30 $ 12 Direct labor 20 15 Variable manufacturing overhead 7 5 Traceable fixed manufacturing overhead...

  • Cane Company manufactures two products called Alpha and Beta that sell for $165 and $130, respectively....

    Cane Company manufactures two products called Alpha and Beta that sell for $165 and $130, respectively. Each product uses only one type of raw material that costs $8 per pound. The company has the capacity to annually produce 113,000 units of each product. Its average cost per unit for each product at this level of activity are given below: Beta $ 24 Alpha $ 40 29 15 Direct materials Direct labor Variable manufacturing overhead Traceable fixed manufacturing overhead Variable selling...

  • Cane Company manufactures two products called Alpha and Beta that sell for $120 and $80 respectively....

    Cane Company manufactures two products called Alpha and Beta that sell for $120 and $80 respectively. Each product uses only one type of raw material that costs $6 per pound. The company has the capacity to produce 100,000 units annually of each product. Its unit costs for each product at this level of activity are as follows:    Alpha Beta Direct Materials $30 $12 Direct Labor 20 15 Variable Manufacturing 7 5 Traceable Fixed Manufacturing 16 18 Variable Selling Expense...

  • Write a Java application that prompts the user for pairs of inputs of a product number...

    Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1    1...

  • Kim Distribution Services (KDS) distributes food purchased in bulk to small retailers. The firm is divided...

    Kim Distribution Services (KDS) distributes food purchased in bulk to small retailers. The firm is divided into two divisions: Purchasing and Distribution. Purchasing is responsible for ordering goods from the manufacturer receiving them, and then moving them to the appropriate location in the warehouse Distribution is responsible for taking orders from retailers, picking the products from the warehouse for the orders, and packaging the orders for shipment. KDS has a policy of filling every order on the day of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT