Need help writing a simple nested if statement in MATLAB. The program needs to assign a grade of an A if a person has a grade of >=90 and simply output that the person would not have an A if their grade is <90. Must used a nested if statement.
x=input('Enter grade in class'); if x>= 90 fprintf('Grade is A') if x<90 fprintf('Grade is below A') end end thats what I have so far but it's not right.
a nested if has something checked inside another thing that's checked. In your code, suppose they have 87. It'll do the first line, and it'll fail to be >=90, and it'll be done. If it's 97, it'll go into the if block (because it's over 90) and then print the output, and then check if it's less than 90, and fail that test. However if would never have gotten there in the first place if it was below 90, so that code is pointless and will never run. THe question is, why must it be nested- it SHOULD be something like: if score >=90 tell them they got an A else tell them they didn't get an A You shouldn't need a nested if. If the assignment is asking for a nested if, then it's silly, but you still have to figure it out- since it's not necessary, it's sort of fudging it just to satisfy the requirements. You could do something like see if the score is > 0, and then inside that see if it was less than 100 and then inside that check for 90... but it seems contrived. Can you include the actual assignment text?
Yea I had some confusion when it came to the assignment but after talking to some classmates I understand it better. You have grades A- F in increments of 10, for instance 89-80 is a B. I must then make a nested if structure for each grade
sorry for the confusion
you still should not need NESTED if's... you can simply use if, else if, else if, etc..., and end with else. So again, why do you need nesting? If you give the actual text of the assignment, we could understand better, but you don't need nesting simply to assign letter grades.
Part 3 number 2
yea I have made elseif and stacked if structures so far and they were far more simple to make
Join our real-time social learning platform and learn together with your friends!