Trying to fix the loop
이전 댓글 표시
I am trying to change my code so when it loops more than five times the error message changes to Invalid vehicle type! Re-enter vehicle type (Compact, Midsize, Truck, Industrial, Military)
I have been trying to just use the variable n>5 under the for loop for this but keep getting error messages
Vehicle_Type=input('Enter the Vehicle Type','s')
for n=1:5
switch Vehicle_Type
case{'compact','Compact'}
fprintf('1\n');
break
case{'midsize','Midsize'}
fprintf('2\n');
break
case{'truck','Truck'}
fprintf('3\n');
break
case{'industrial','Industrial'}
fprintf('4\n');
break
case{'military','Military'}
fprintf('4\n');
break
otherwise
fprintf('Vehicle type is not recognized. The program stops. Rerun the program again\n')
end
end
댓글 수: 1
Awais Saeed
2021년 11월 16일
what actually are you trying to do? Your loop does not make any sense. Your user input should be inside the loop to ask for the input for all iterations.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Multirate and Multistage Filters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!