필터 지우기
필터 지우기

Switch case structure, I needed to show all units in this excercise

조회 수: 1 (최근 30일)
Valters
Valters 2023년 1월 5일
편집: Fangjun Jiang 2023년 1월 5일
How to fix this, I want to display all the units for this switch structure to work!
  댓글 수: 3
Valters
Valters 2023년 1월 5일
vienibas = 3;
switch vienibas
case vienibas <= 2
disp ('pirmacena = vienibas * 130')
case vienibas <= 5
disp ('otracena = vienibas * 160')
case vienibas >= 5
disp ('tresacena = vienibas * 200')
if vienibas < 3
pirmacena = vienibas * 130;
elseif prece < 5
otracena = vienibas * 160;
else
tresacena = vienibas * 200;
end
end
pirmacena - is first price = units * 130
otracena - is second price = units * 160
tresacena - is third price = units * 200
And all other things you understand I hope
Dyuman Joshi
Dyuman Joshi 2023년 1월 5일
What exactly are you trying to do?
Say the value of vienibas is 3. What should be the output?
And are the last three lines part of the code or are they the result you are expecting?

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 1월 5일
편집: Fangjun Jiang 2023년 1월 5일
use if-elseif,
When you have logical comparison in the case statement, it results in true or false (1 or 0 in value). The resulting effect is not what you think it is.
It is a mis-understanding of the switch-case programming. Please read the help document and look at the examples.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by