MATLAB Answers

while loops with and conditions (repeat until conditions are met)

4 views (last 30 days)
Mariam Al Zarouni
Mariam Al Zarouni on 7 Apr 2020
Commented: Mehmed Saad on 8 Apr 2020
This question was flagged by darova
Hello everyone
I'm not the best in coding but i'm trying hard. So basically, i need a code where i can prompt the user to enter any random, real, and positive value only.(number of values must be EVEN).
For example:
the user would enter: 1 4 5
the output would be: re-enter your values as their number must be even
the user would re-enter: 1 4 5 3
and the loop will continue in this case
I hope you got my point and could assist me hence i'm really struggling and haven't got much time

  8 Comments

Show 5 older comments
Mariam Al Zarouni
Mariam Al Zarouni on 7 Apr 2020
Another code was this: I get the same error here too. I also want to add another condition in the while loop which is the number of value must be even as i mentioned earlier but i didn't know where or how to put it. I know for even m(m,2)==0
close all;
Resistors=input(' Enter values of two resistances in ohm [R1 R2]= '); % to enter the values of the resistors
Total=length(Resistors);
[row,column]=size(Resistors);% matrix of the resistors
if isreal(Resistors) && row==1 && column>=2 % this is to make sure the values are real and the matrix is one row and infinite number of columns (values)
for number=1:Total
if Resistors(number)>0 % value of the resistor is positive or otherwise
equation=true;
else if Resistors(number)<=0
equation=false;
break;
end
end
end
end
if equation==false
disp(' invalid numbers .... please enter valid numbers')
end
end
disp ('===================================================================')
Mariam Al Zarouni
Mariam Al Zarouni on 7 Apr 2020
Okay Muhammad,I got my output. Can i just show you what my final output should look like?

Sign in to comment.

Answers (0)

Sign in to answer this question.


Translated by