I want to add some of requiring to my codes ? How can I ?
조회 수: 1 (최근 30일)
이전 댓글 표시
n=input('Please enter the number of pizzas to order: ');
disp(n);
while(n<=0)
n=input('value should be atleast 1 pizza to continue ordering. ');
disp(n);
end
TotalPrice=0;
for i=1:n
%fprintf("\nPizza %d",i)
SizeOfPizza=input('please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):');
disp(SizeOfPizza);
while( SizeOfPizza>3)
SizeOfPizza=input('Invalid Entry!Enter size of pizza (Small-1),(Medium-2),(Large-3): ');
disp(SizeOfPizza);
end
if(SizeOfPizza==1)
TotalPrice= TotalPrice+30;
elseif (SizeOfPizza==2)
TotalPrice=TotalPrice+40;
elseif (SizeOfPizza==3)
TotalPrice=TotalPrice+50;
else
SizeOfPizza=input(' Invalid Entry!!Please choose the size of pizza L or M or S? ','s');
end
end;
Topping=input('Please enter the number of Toppings(Its free for first 3 Toppings):');
disp(Topping);
TotalPrice= TotalPrice + 3* (Topping-3);
%calculate topping values if 3 ten topping-3=0 so it would come to toal price only
fprintf('The total value of your %d pizza orders is $ %.3f\n',n,TotalPrice);
I did these codes about ( order , size, price of Topping and calculate the total price ) . And I want to add some orders to them but I do not know how ? can you help me to add them ?
1-Type (different flavors of Pizza). Pizza type can be (pepperoni, margherita, vegetarian, Neapolitan). Your program needs to support adding new types of pizza as well.
2- Type of Toppings can include (olives, tomatoes, mushrooms, jalapenos, chicken, beef, pepperoni) .
3- Drinks (Number of drinks). Drinks can be (Coke, Diet Coke, Coke Zero, Pepsi, Diet Pepsi, 3AED) , (Water, 1 AED), (Fresh Juice, 5 AED).
4- Order number (Order Number). An order number should be generated for each order. The order number should be the combination of Customers name plus current date i.e.,NameDDMMYYYY.
댓글 수: 0
답변 (2개)
KALYAN ACHARJYA
2020년 8월 1일
편집: KALYAN ACHARJYA
2020년 8월 1일
while n<=0
n=input('Please enter the number of pizzas to order: ');
if n<=0
disp('Value should be atleast 1 pizza to continue ordering....');
end
end
TotalPrice=zeros(1,n);
for i=1:n
SizeOfPizza=input('please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):');
while SizeOfPizza>3 || SizeOfPizza<1
disp('Invalid Entry!Enter size of pizza (Small-1),(Medium-2),(Large-3)....');
disp('Please Try again.....');
SizeOfPizza=input('please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):');
end
if SizeOfPizza==1
TotalPrice(i)=30;
elseif SizeOfPizza==2
TotalPrice(i)=40;
else
TotalPrice(i)=50;
end
end
Topping=input('Please enter the number of Toppings(Its free for first 3 Toppings):');
TotalPrice=sum(TotalPrice)+3* (Topping-3);
%calculate topping values if 3 then topping-3=0 so it would come to toal price only
fprintf('The total value of your %d pizza orders is $ %.3f\n',n,TotalPrice);
Verified
Please enter the number of pizzas to order: 2
please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):2
please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):3
Please enter the number of Toppings(Its free for first 3 Toppings):4
The total value of your 2 pizza orders is $ 93.000
>>
댓글 수: 1
KALYAN ACHARJYA
2020년 8월 1일
With Customer ID
name_customer=input('Name Please: ','s');
n=0;
while n<=0
n=input('Please enter the number of pizzas to order: ');
if n<=0
disp('Value should be atleast 1 pizza to continue ordering....');
end
end
TotalPrice=zeros(1,n);
for i=1:n
SizeOfPizza=input('please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):');
while SizeOfPizza>3 || SizeOfPizza<1
disp('Invalid Entry!Enter size of pizza (Small-1),(Medium-2),(Large-3)....');
disp('Please Try again.....');
SizeOfPizza=input('please enter the size of pizza(Small enter 1),(Medium enter 2),(Large enter 3):');
end
if SizeOfPizza==1
TotalPrice(i)=30;
elseif SizeOfPizza==2
TotalPrice(i)=40;
else
TotalPrice(i)=50;
end
end
Topping=input('Please enter the number of Toppings(Its free for first 3 Toppings):');
TotalPrice=sum(TotalPrice)+3* (Topping-3);
%calculate topping values if 3 then topping-3=0 so it would come to toal price only
fprintf('Oder Number %s, & total value of your %d pizza orders is $ %.3f\n',[name_customer,date],n,TotalPrice);
Image Analyst
2020년 8월 1일
Here's a start:
customerName = 'Customer'
again = true;
numberOfItems = 0;
maxItems = 30; % Failsafe.
while again && numberOfItems <= maxItems
% Ask user and add to order....
% input(.............. customerName = whateve.
% Increment item count and bail out if they hit the max.
numberOfItems = numberOfItems + 1;
if numberOfItems >= maxItems
break; % Failsafe to prevent infinite loops.
end
% Now ask if they're done.
promptMessage = sprintf('You now have %d items.\nDo you want to add another item\nor check out now?', numberOfItems);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Add item', 'Check out', 'Add item');
if contains(buttonText, 'Check', 'IgnoreCase', true)
break;
end
end
orderID = sprintf('%s%s', customerName, datestr(now, "DDMMYYYY"))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!