No-Input: Error Checking Problem
이전 댓글 표시
clear, clc
disp('Welcome to Basic Conversion Script');
prompt = 'Please input t for Temperature, l for Length, or m for Mass: ';
z = input (prompt, 's');
w = isempty(z);
if w == 0
disp('Error! There is not input');
end
while ~(z == 't' || z == 'l' || z == 'm')
z = input ('Error! Please input wanted values again: ', 's');
w = isempty(z);
if w == 0
disp('Error! There is not input');
end
end
if strcmp(z,'t')
disp('1. To Convert Celsius to Fahrenheit' );
disp('--');
disp('2. To Convert Fahrenheit to Celsius ');
x = input('Please choose a number betwenn 1 or 2: ');
w = isempty(x);
if w == 0
disp('Error! There is not input');
end
while ~(x == 1 || x == 2)
if strcmp(x, 's')
x = input ('Error! Please choose a number betwenn 1 or 2 again: ');
elseif (x < 0) %This if-statement is error checking for any negative values
x = input ('Error! Please choose a number betwenn 1 or 2 again: ');
else
x = input ('Error! Please choose a number betwenn 1 or 2 again: ');
end
end
if x == 1
C = input('Enter the Temperatue in Celsius: ');
w = isempty(C);
if w == 1
disp('Please Input a number to convert next time');
end
F = (C * 9/5) + 32;
fprintf('The Temperature in Fahrenheit is: %1.2f\n', F );
fprintf(1, '\n');
end
if x==2
F = input('Enter the Temperatue in Fahrenheit: ');
w = isempty(F);
if w == 1
disp('Please Input a number to convert next time');
end
C = (F - 32) * 5/9;
fprintf('The Temperature in Celcius is: %1.2f\n', C );
fprintf(1, '\n');
end
end
So I'm currently creating a conversion script. And I'm currently trying to do a error check that makes sure it sends out an a error message when the user doesn't input anything.
The error I get is:
Operands to the || and && operators must be convertible to logical scalar values.
Error in Milestone2 (line 11)
while ~(z == 't' || z == 'l' || z == 'm')
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Third-Party Cluster Configuration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!