For part of my assignment we have to ask for a number range between .1 and 0.1 and so I wrote my code as seen below. When I run it I get the following error message from the line I underlined.
"Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses."
How can I make the while loop check that y is between .1 and .01
y = input('Please type in the selected accuracy (must be between .1 and .01)');
while(y>0.1 or y<0.01)
disp('Sorry, that value is not within the acceptable range');
y = input('Please input a value that is within the acceptable range');
end

 採用された回答

DGM
DGM 2021 年 5 月 4 日

1 投票

y = input('Please type in the selected accuracy (must be between .1 and .01): ');
while isempty(y) || y>0.1 || y<0.01
disp('Sorry, that value is not within the acceptable range');
y = input('Please input a value that is within the acceptable range: ');
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2021 年 5 月 3 日

回答済み:

DGM
2021 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by