# Write a function called eligible that helps the admission officer of the Graduate School decide whether the applicant is eligible for admission based on GRE scores. The function takes two positive scalars called v and q as in

153 views (last 30 days)
Moeez ur Rehman Qureshi on 11 Jul 2019
Commented: DGM on 12 Oct 2022
if v>=92 && q>=88;
fprintf('true')
else
fprintf('false')
end
Mir Umar on 22 Aug 2021
avperc = mean([v,q]);
if avperc>= 92 && (v>88&&q>88)
end

VIGNESH B S on 13 Oct 2021
function res = eligible(v,q)
pass = logical(0);
avg = (v+q)/2;
if (avg>= 92 && v >88 && q>88)
pass = logical(1);
end
res = pass;
end

Steven Lord on 11 Jul 2019
Nowhere in your function do you define the variable admit the function returns as its output. You haven't shown the full text of the homework question but I suspect it tells you to have your function return true or false instead of printing the text "true" or "false". To do that assign a value to the variable.
Walter Roberson on 23 Sep 2019
q and v are numeric values. When you use the && operator between them, admit=q&&v is defined as
if q ~= 0
if v ~= 0
else
end
else
end
However, the assignment makes no mention of testing for zero or not.
In particular when you get to your else branch, admit=~q&&v then that would be true if q was 0 and v was non-zero, leading you to admit someone with a score of 0 for q when the assignment would require that they be rejected because 0>88 is false.

Jake Armitage on 14 Apr 2021
After enough struggle I am wondering who can help me understand why I'm returning errors from this program. Thanks
avperc = mean([v,q]);
if avperc>= 92 && (v&&q>88)
end
end
Rik on 7 Jul 2021
One closes the if, the other closes the program.
While using an end to close the program is optional, it is recommended that you do. If functions are explicitly closed with an end, you can use nested functions and you can define local functions in a script.

Tushar Nagar on 13 Dec 2021
avg=(v+q)/2;
rv=false;rq=false;
if v>88 && avg>=92
rv=true;
end
if q>88 && avg>=92
rq=true;
end

Ankit Sharma on 14 Jun 2022
avg=(v+q)/2;
if (v>88 && avg>=92)&& (q>88 && avg>=92)
else
end
end
Rik on 17 Jun 2022
Why didn't you post this commented version as the original answer? This question is not meant to harrass you in any way, I just want to understand your motivation. I simply don't see why you would post yet another solution to a homework question. What are people meant to learn from that?

Alexandar on 28 Jun 2022
avg = (v+q)/2;
if avg > 92
elseif v >= 88 && q >= 88
end
I have no clue why this keeps failing. Can somebody please explain why?
##### 2 CommentsShowHide 1 older comment
Idris jae on 25 Sep 2022
Thank you for bringing this here. All this while the solution was in the error message '' the variable admit must be a logical data type".
avg= (v+q)/2;
if (avg>=92) && (v>88 && q>88)
admit=logical(1); %most previous contributions here are thesame except at this point
else
end

Idris jae on 25 Sep 2022
avg= (v+q)/2;
if (avg>=92) && (v>88 && q>88)
admit=logical(1); %most previous contributions here are thesame except at this point
else
end
Walter Roberson on 25 Sep 2022
logical(1) can be written as true and logical(0) can be rewritten as false

Arah Cristal on 12 Oct 2022
avg = (v+q)/2;
if (avg>=92 && v>88 && q>88);
else
end
DGM on 12 Oct 2022
The output of the combined comparisons is a logical value, so there really isn't any need to conditionally assign the output. You already have it.
avg = (v+q)/2;
admit = avg>=92 && v>88 && q>88;
end

### Categories

Find more on Matrix Indexing 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!