필터 지우기
필터 지우기

repeating a sequence of code

조회 수: 4 (최근 30일)
Bradley Johnson
Bradley Johnson 2020년 2월 25일
답변: Alex Mcaulley 2020년 2월 25일
Hello,
I am working on an assignment for a class, I have a program written as follows,
disp(' Choose an Option Below ');
disp(' 1 Convert Decimal Number to Binary Number');
disp(' 2 Convert Binary Number to Decimal Number');
disp(' 3 Exit');
n = input(' Enter Option Number You Desire: ');
switch n
case 1
fprintf(' Convert Decimal Number to Binary Number\n');
a = input(' Please enter a whole decimal number: ');
bradleyJohnsonD2B(a)
case 2
fprintf(' Convert Binary Number to Decimal Number\n');
b = input(' Please enter a binary string : ');
johnsonBradleyB2D(b)
case 3
fprintf( ' Thank you for using my program !!\n ');
otherwise
fprintf( ' You Selected an Invalid Option, Please Choose Again ');
end
I need this program to start over or repeat its self from the beginning for every option other than case three. how would I go about doing that.

채택된 답변

Alex Mcaulley
Alex Mcaulley 2020년 2월 25일
Do you mean this?
n = 1;
while n ~= 3
disp(' Choose an Option Below ');
disp(' 1 Convert Decimal Number to Binary Number');
disp(' 2 Convert Binary Number to Decimal Number');
disp(' 3 Exit');
n = input(' Enter Option Number You Desire: ');
switch n
case 1
fprintf(' Convert Decimal Number to Binary Number\n');
a = input(' Please enter a whole decimal number: ');
bradleyJohnsonD2B(a)
case 2
fprintf(' Convert Binary Number to Decimal Number\n');
b = input(' Please enter a binary string : ');
johnsonBradleyB2D(b)
case 3
fprintf( ' Thank you for using my program !!\n ');
otherwise
fprintf( ' You Selected an Invalid Option, Please Choose Again ');
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by