i don't understand

11 Ansichten (letzte 30 Tage)
doron kra
doron kra am 30 Mai 2020
Kommentiert: doron kra am 31 Mai 2020
hi,
i was asked to write a simple function for home work :
this was my code:
function [admit]=eligible(v,q)
avg=(v+q)/2;
if (avg>=92) && (v>88) && (q>88)
admit=1;
else
admit=0;
end
end
and i don't understand why i got this error message :
please advise what is the problem.
thank's

Akzeptierte Antwort

madhan ravi
madhan ravi am 30 Mai 2020
Replace 1 with ~0 and 0 with ~1.
  6 Kommentare
Stephen23
Stephen23 am 31 Mai 2020
Rather than obfuscated code using negations of numeric values, it is clearer to write true and false:, i.e.:
admit = true;
Note that you can trivially replace the entire if-else-end statement:
admit = (avg>=92) && (v>88) && (q>88);
doron kra
doron kra am 31 Mai 2020
Wow, this is very elegant !
thanks for showing me that :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming 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!

Translated by