How to run a loop with isNaN
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Benjamin
am 17 Okt. 2022
Kommentiert: Benjamin
am 18 Okt. 2022
How would i make a loop where if a positive number isnt inputted, The question is asked again?
4 Kommentare
Davide Masiello
am 17 Okt. 2022
Bearbeitet: Davide Masiello
am 17 Okt. 2022
Your code seems fine, just remove the line
a =~ NaN;
and it works, meaning that if you input a = nan then it'll display the 'Please only enter a numerical value for a: ' message.
Akzeptierte Antwort
Davide Masiello
am 17 Okt. 2022
Bearbeitet: Davide Masiello
am 17 Okt. 2022
disp('Solving a quadratic polynonial (ax^2+bx+c), where a b and c are real numbers to 3 decimal places')
a = input ('What is your value for a?: '); %coefficient of x^2
while ~isnumeric(a) || isnan(a)
a = input ('Please only enter a numerical value for a: ');
end
Solving a quadratic polynonial (ax^2+bx+c), where a b and c are real numbers to 3 decimal places
What is your value for a?: nan
Please only enter a numerical value for a: 'a'
Please only enter a numerical value for a: 2
>>
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!