How can I do a height comparison

7 visualizaciones (últimos 30 días)
Katie
Katie el 13 de Oct. de 2013
Editada: Image Analyst el 13 de Oct. de 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?

Respuestas (1)

Image Analyst
Image Analyst el 13 de Oct. de 2013
Editada: Image Analyst el 13 de Oct. de 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.

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by