In: Computer Science
fix all errors in code below: PLEASE DO ASAP, THIS IS IN MATLAB
%Welcome Message
fprintf('****Welcome to Comida Mexicana De Mentiras****\n');
flag =0;
while flag ==1
% Asking the user for the order
choice = input('Please enter your order \n 1. Burrito Bowl \n 2.Burrito \n 3. Tacos \n Enter 1 or 2 or 3: ','s'); switch choice
case choice==1
% For Burrito Bowl
BaseCost = 4;
[Protein, PC] = proteinChoice();
[FinalAmount,~]= AmountCalculator(BaseCost,PC); displayMessage("Burrito Bowl",Protein,FinalAmount);
case choice==2
end
end
% For Burrito
BaseCost = 5;
[Protein, PC] = proteinChoice(); [FinalAmount,~] = AmountCalculator(BaseCost,PC); displayMessage("Burrito",Protein,FinalAmount);
for proteinChoice == 3 % For Tacos
BaseCost = 3;
[Protein, PC] = proteinChoice(); [FinalAmount,~] = AmountCalculator(BaseCost,PC); displayMessage("Tacos",Protein,FinalAmount);
else
%If the user enters a choice which is not 1, 2 or 3
fprintf('Please enter a valid choice \n');
% Giving the user an option to re-enter their order
flag = input('Would you like to re-enter your order? Enter 1 for yes and 0 for no:\n');
end
% This zero input, two output function is used to get the user's protein
% choice
function [Protein,PC] = proteinChoice()
Protein_Option = input('Enter your choice of Protein: \n 1. Chicken \n 2. Steak \n 3. Carnitas \n 4. Sofritas \n 5. Veggie \n');
% PC refers to Protein cost, which is the cost of the protein add on switch Protein_Option
case 1
PC = 2;
Protein
case 2
PC = 2;
Protein
case 3
PC = 2;
Protein
case 4
PC = 1;
Protein
case 5
= "Chicken"; = "Steak";
= "Carnitas"; = "Sofritas";
PC = 0;
Protein = "Veggie";
% The following two input, one output function is used to calculate the
% total cost including tax for the order.
function FinalAmt = AmountCalculator(BC,PC)
% CostAdder and TaxCalc are anonymous functions
% The calculations in the following anonymous functions are correct, but
% the syntax is not.
@CostAdder = (x) sum(x);
@TaxCalc = (x) 0.075*x; % Assuming a 7.5% tax rate
TotalCost = CostAdder([BC,PC]);
Tax = TaxCalc(TotalCost);
FinalAmt = CostAdder([TotalCost, Tax]);
end
% This three input, zero output function is used to display the total cost
% to the user.
function displayMessage(BaseOrder,Protein,FA)
disp(' Your %f %f cost $%.2f\n',Protein,BaseOrder,FA); end
clc;%Welcome Message
fprintf('****Welcome to Comida Mexicana De Mentiras****\n');
flag = 1;
while flag ==1
% Asking the user for the order
choice = input('Please enter your order \n 1. Burrito Bowl \n 2.Burrito \n 3. Tacos \n Enter 1 or 2 or 3: ','s');
switch choice
case '1'
% For Burrito Bowl
BaseCost = 4;
[Protein, PC] = proteinChoice();
FinalAmount= AmountCalculator(BaseCost,PC); displayMessage("Burrito Bowl",Protein,FinalAmount);
case '2'
% end
% For Burrito
BaseCost = 5;
[Protein, PC] = proteinChoice(); FinalAmount = AmountCalculator(BaseCost,PC);
displayMessage("Burrito",Protein,FinalAmount);
case '3' % For Tacos
BaseCost = 3;
[Protein, PC] = proteinChoice(); FinalAmount = AmountCalculator(BaseCost,PC); displayMessage("Tacos",Protein,FinalAmount);
otherwise
%If the user enters a choice which is not 1, 2 or 3
fprintf('Please enter a valid choice \n');
end
% Giving the user an option to re-enter their order
flag = input('Would you like to re-enter your order? Enter 1 for yes and 0 for no:\n');
end
% This zero input, two output function is used to get the user's protein
% choice
function [Protein,PC] = proteinChoice()
Protein_Option = input('Enter your choice of Protein: \n 1. Chicken \n 2. Steak \n 3. Carnitas \n 4. Sofritas \n 5. Veggie \n');
switch Protein_Option
% PC refers to Protein cost, which is the cost of the protein add on switch Protein_Option
case 1
PC = 2;
Protein = 'Chicken';
case 2
PC = 2;
Protein = 'Steak';
case 3
PC = 2;
Protein = 'Carnitas';
case 4
PC = 1;
Protein = 'Sofritas';
case 5
PC = 0;
Protein = "Veggie";
end
end
% The following two input, one output function is used to calculate the
% total cost including tax for the order.
function FinalAmt = AmountCalculator(BC,PC)
% CostAdder and TaxCalc are anonymous functions
% The calculations in the following anonymous functions are correct, but
% the syntax is not.
CostAdder = @(x) sum(x);
TaxCalc = @(x) 0.075*x; % Assuming a 7.5% tax rate
TotalCost = CostAdder([BC,PC]);
Tax = TaxCalc(TotalCost);
FinalAmt = CostAdder([TotalCost, Tax]);
end
% This three input, zero output function is used to display the total cost
% to the user.
function displayMessage(BaseOrder,Protein,FA)
fprintf(' Your %s %s cost $%.2f\n',BaseOrder,Protein,FA); end
%output
----------------------------------------------------------------------------------------------------
Your ThumbsUp on this answer matters to me a lot :)
----------------------------------------------------------------------------------------------------
For any further clarifications, reach out in the comments
section