How to connect two displays?

조회 수: 1 (최근 30일)
Minhao Wang
Minhao Wang 2020년 9월 25일
댓글: Minhao Wang 2020년 9월 25일
clc;clear
C1 = input('Please enter a code to break: ' , 's');
if length(C1) ~= 6
disp('Decoy message: Not a six-digit number.');
else
A = mod(sum(C1 - '0'),2);
end
if A == 1
disp('Decoy message: Sum is odd.')
else
C2 = (C1(1) - '0') * (C1(2) - '0') - (C1(3) - '0');
end
switch C2
case 1
disp('Rescue on Monday')
case 2
disp('Rescue on Tuesday')
case 3
disp('Rescue on Wednesday')
case 4
disp('Rescue on Thursday')
case 5
disp('Rescue on Friday')
case 6
disp('Rescue on Saturday')
case 7
disp('Rescue on Sunday')
otherwise
disp('Decoy message:Invalid rescue day.');
end
F1 = str2num(C1(4));
F2 = str2num(C1(5));
F3 = str2num(C1(6));
if mod(F1,3) == 0
B = F2 - F3;
else
B = F3 - F2;
end
switch(B)
case 1
disp('at the bridge.');
case 2
disp('at the library.');
case 3
disp('at the river crossing.');
case 4
disp('at the airport.');
case 5
disp('at the bus terminal.');
case 6
disp('at the hospital.');
case 7
disp('at the St. Petes Church.');
otherwise
disp('Decoy message:Invalid rendezvous point.');
end
If we run this Script and enter 510129,it will appear:
Please enter a code to break: 510129
Rescue on Friday
at the St. Petes Church.
But I would like to make it appear :
Please enter a code to break: 510129
Rescue on Friday at the St. Petes Church.
How do I do that?

채택된 답변

KSSV
KSSV 2020년 9월 25일
편집: KSSV 2020년 9월 25일
clc;clear
C1 = input('Please enter a code to break: ' , 's');
if length(C1) ~= 6
disp('Decoy message: Not a six-digit number.');
else
A = mod(sum(C1 - '0'),2);
end
if A == 1
disp('Decoy message: Sum is odd.')
else
C2 = (C1(1) - '0') * (C1(2) - '0') - (C1(3) - '0');
end
switch C2
case 1
str1 = 'Rescue on Monday' ;
case 2
str1 = 'Rescue on Tuesday' ;
case 3
str1 = 'Rescue on Wednesday' ;
case 4
str1 = 'Rescue on Thursday' ;
case 5
str1 = 'Rescue on Friday' ;
case 6
str1 = 'Rescue on Saturday' ;
case 7
str1 = 'Rescue on Sunday' ;
otherwise
str1 = 'Decoy message:Invalid rescue day.' ;
end
F1 = str2num(C1(4));
F2 = str2num(C1(5));
F3 = str2num(C1(6));
if mod(F1,3) == 0
B = F2 - F3;
else
B = F3 - F2;
end
switch(B)
case 1
str2 = ('at the bridge.');
case 2
str2 = ('at the library.');
case 3
str2 = ('at the river crossing.');
case 4
str2 = ('at the airport.');
case 5
str2 = ('at the bus terminal.');
case 6
str2 = ('at the hospital.');
case 7
str2 = ('at the St. Petes Church.');
otherwise
str2 = ('Decoy message:Invalid rendezvous point.');
end
str = [str1,' ', str2] ;
fprintf("%s\n",str) ;
  댓글 수: 1
Minhao Wang
Minhao Wang 2020년 9월 25일
Thank you so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by