How can I do a height comparison
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Image Analyst
am 13 Okt. 2013
Bearbeitet: Image Analyst
am 13 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!