****** USE MATLAB ********** 5. The Bits-n-Bytes computer system is malfunctioni
ID: 2293627 • Letter: #
Question
****** USE MATLAB **********
5. The Bits-n-Bytes computer system is malfunctioning and they need your help to make it work. Write a code that can determine if a customer is allowed to use their meal plan to purchase food. Assume that meal plans follow the given conditions: You are allowed 15 meals during the week. Each meal must be within the following price limits: • Breakfast: $5.77 • Lunch: $7.98 • Dinner: $9.53 Use input or menu commands to determine the following information about the current customer: • How many meals have they already used this week? • Is it breakfast, lunch, or dinner? • What is the total cost of their items? Based upon the input information, display an appropriate message telling the customer what happened after you swiped their card. (Tell them they don't have any meals left, or tell them their items are too expensive, or tell them the transaction was completed successfully.)Explanation / Answer
Prompt={'BreakFasts Completed','Lunchs Completed','Dinners Completed','What you need Now'};
% For 'what you need' enter
% 1 - For breakfast
% 2 - Lunch
% 3 - Dinner
Data=inputdlg(Prompt,'Enter Meals Data');
Cost=[5.77 7.98 9.53]; % cost of each meal Breakfast, Lunch and Dinner
datachar=cell2mat(Data);
datanum=str2num(datachar);
Nbr=datanum(1); % Number of Breakfasts
Nlu=datanum(2); % Number of Lunchs
Ndi=datanum(3); % Number of Dinner
Tmeals=Nbr+Nlu+Ndi; % Total number of Meals already used this week
Tcost=Nbr*datanum(1)+Nlu*datanum(2)+Ndi*datanum(3); % Total cost before this week
meal=datanum(4);
switch meal
case 1
Tnew=Tcost+Cost(1);
case 2
Tnew=Tcost+Cost(2);
case 3
Tnew=Tcost+Cost(3);
end
%
fprintf('Number of meals already used by you are: %d ',Tmeals);
fprintf('Total cost of their items: %d ',Tcost);
if Tmeals>=15
msgbox('You dont have any meals left this week');
elseif Tnew>100
msgbox('Your items are too expensive');
else
msgbox('Your transaction is succusful');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.