MATLAB Answers

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

887 views (last 30 days)
Moeez ur Rehman Qureshi
Moeez ur Rehman Qureshi on 11 Jul 2019
Commented: Image Analyst on 6 Sep 2020 at 15:32
function admit=eligible(v,q);
if v>=92 && q>=88;
fprintf('true')
else
fprintf('false')
end

  6 Comments

Show 3 older comments

Sign in to comment.

Answers (12)

Yamen Al-Jajan
Yamen Al-Jajan on 24 Nov 2019
function admit=eligible(v,q)
if v>88 & q>88
ave=(v+q)/2;
if ave>=92
admit=true;
else
admit=false;
end
else
admit=false;
end

  1 Comment

Rik
Rik on 24 Nov 2019
Why are you providing a complete working solution to a homework question? Given that this is 2 months old, cheating is probably not really an issue, but future students with the same assignment can just copy your code without learning anything, which means they will need your help for every future project as well.

Sign in to comment.


Steven Lord
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.
admit = true;
admit = false;

  8 Comments

Show 5 older comments
Walter Roberson
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
admit = true;
else
admit = false;
end
else
admit = false;
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.

Sign in to comment.


evan muas
evan muas on 9 Dec 2019
function admit= eligible(v,q)
if (v+q)/2>=92
if v>88 && q>88
admit=true;
else
admit=false;
end
else
admit=false;
end

  0 Comments

Sign in to comment.



mohammad elyoussef
mohammad elyoussef on 4 Apr 2020
function f = eligible(a,b)
c = median(a+b);
if c >= 92 && a > 88 && b> 88
f = true;
else
f = false;
end

  1 Comment

Walter Roberson
Walter Roberson on 22 May 2020
The question requires that the average of the two grades is used, but you are taking the sum of the two grades. The sum of the two is a scalar, and the median() of a scalar is the same scalar.

Sign in to comment.


muyiwabowen
muyiwabowen on 22 May 2020
function admit= eligible(v, q)
a = mean([v q])
if a>=92 && v>88 && q>88
admit=true
else
admit=false
end

  0 Comments

Sign in to comment.


Aasma Shaikh
Aasma Shaikh on 26 May 2020
Edited: Aasma Shaikh on 26 May 2020
function admit = eligible (v, q)
avg= (v+q)/2;
if ((avg>=92) && ((v >88) && (q>88)))
admit= true;
else
admit = false;
end %----- COPY, PASTE AND RUN THIS DIRECTLY

  0 Comments

Sign in to comment.



ROHAN SUTRADHAR
ROHAN SUTRADHAR on 7 Jun 2020
function admit = eligible(v,q)
x = ((v+q)/2);
if (x>=92)&&((v>88)&&(q>88));
admit = true;
else
admit = false;
end

  0 Comments

Sign in to comment.


Bhavesh Gole
Bhavesh Gole on 3 Aug 2020
function admit = eligible(v,q)
k =(v+q)/2;
if (k>=92 && v>88 && q>88)
admit = true;
else
admit = false;
end
end

  0 Comments

Sign in to comment.


Dinesh Nali
Dinesh Nali on 28 Aug 2020 at 17:35
function admit=eligible(v, q)
% average of verbal and quantitative
average_score = (v+q)/2;
% logical and condition for admission
if average_score>=92 && v>88 && q>88
admit = true;
else
admit = false;
end

  2 Comments

Dinesh Nali
Dinesh Nali on 29 Aug 2020 at 4:25
Hi Sir, I have given the solution to the question asked. I have tried the soluition in the Matlab and then given the solution. If you think it is either wrong or the solution is not upto mark, please the choice is your's , you can delete this answer.
I thought to help others, what ever i know in the fundamentals.
Thanks and regards

Sign in to comment.


Khom Raj Thapa Magar
Khom Raj Thapa Magar on 6 Sep 2020 at 9:36
function admit = eligible(v,q)
avg = (v+q)/2;
if (avg >= 92) && (v>88 & q>88)
admit = true;
else
admit = false;
end
Easiest way to tackle with the problem

  1 Comment

Image Analyst
Image Analyst on 6 Sep 2020 at 15:32
Not the simplest. And your answer, but with the correct number of &, has already been posted. I think the simplest is
function admit = eligible(v, q)
admit = (v+q)/2 >= 92 && v > 88 && q > 88;

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by