How can I do a height comparison

13 vues (au cours des 30 derniers jours)
Katie
Katie le 13 Oct 2013
Modifié(e) : Image Analyst le 13 Oct 2013
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?

Réponses (1)

Image Analyst
Image Analyst le 13 Oct 2013
Modifié(e) : Image Analyst le 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.

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by