How to display a menu if the entered value is true and at end of each option

3 Ansichten (letzte 30 Tage)
I am using a function to verify an entered value from csv file, so if the entered value is true the program should display a menu. If it is false it will display a message to re-enter a valid value from the csv file. How can I display the menu again after entering a false value then true one? I tried to use a while loop but it seems not working. I also want to display the menu at the end of each option in the menu. Any ideas about how to do so?
  1 Kommentar
Adnan Fino
Adnan Fino am 14 Dez. 2021
data = Customerdata;
CustomerNumber = input('Enter your Number');
if verifyCustomerNumber (CustomerNumber,data)
disp('True')
m = input('choose: 1:Option 1 2:Option2 3:Option3');
switch m
case 1
case 2
case 3
end
else
disp('False')
CustomerNumber = input("Please enter a valid number");
end
function isValid = verifyCustomerNumber(CustomerNumber,data)
isValid = ismember (CustomerNumber, data{:,"CustomerNumber"});
This is part of my code to verify the customer number, just I would like to know to can I display this menu after entering a wrong number then right number and how to display it at the end of each option. Thanks

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Prince Kumar
Prince Kumar am 19 Jan. 2022
Hi,
You can do it using 'while' loop and 'break' statement. Once you have achieved the desired result you can use 'break' statement to get out of the loop.
Here is an example where the code keep asking for a number until the user enter 4 as input(which is the desired result) :
data = 4;
m = input('Enter a number : ');
while true
if m == data
disp('True');
break;
else
disp('False');
m = input('Enter a number : ');
end
end
I hope you find the above example useful.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by