How can I do a height comparison
조회 수: 6 (최근 30일)
이전 댓글 표시
1. Im supposed to creater a Matlab program and call it "Height3Comparison" for 3 people and
-input the height of person 1 as P!
-input the height of person 2 as P2
- input the height of person 3 as P3
-If person 1 is taller among the three, display "Person 1 is the tallest"
-If person 2 is taller among the three, display "Person 2 is the tallest"
-If person 3 is taller among the three, display "Person 3 is the tallest"
-ignore the tie
2. then Im have to make another program called "Height3ComparisonTie" and do the following
-If person 1 and person 2 have same height, display "persons 1 & 2 are tie"
-If person 2 and person 3 have same height, display "persons 2 & 3 are tie"
-If person 1 and person 3 have same height, display "persons 1 & 3 are tie"
-If person 1 and person 2 and person3 have same height, display "All are tie"
I have no idea how to even accomplish this, i have tried and i just keep getting errors. Can someone please help me out or just give me a hint of where to begin?
댓글 수: 0
답변 (1개)
Image Analyst
2013년 10월 13일
편집: Image Analyst
2013년 10월 13일
Hints:
Use inputdlg() to ask the user for the heights. Then use sort()
[sortedHeights, sortOrder] = sort([P1, P2, P3], 'Descend');
fprintf('Person %d is the tallest\n', sortOrder(1));
Of course you could also use a bunch of if statements also.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!