How can I do a height comparison
14 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 13 Oct 2013
Edited: Image Analyst
on 13 Oct 2013
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 Comments
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!