how to make 3 differents inputs with if else statement
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I want to ake simpel program which has 3 deifferent input. The first thing is you input 3 value of each input, then the results is 3 output with the grade each ouput.
tis the program
Toefl=input('Toefl=')
Math=input('Mathematic=')
Bio=input('Biologi=')
if((Toefl >= 601) && (Toefl <= 670)) && ((Math >= 601) && (Math <= 670)) && ((Bio >= 601) && (Bio <= 670))
disp ('Excellent')
elseif ((Toefl >= 501) && (Toefl <= 600)) && (((Math >= 501) && (Math <= 600)) && ((Bio >= 501) && (Bio <= 600)))
disp ('Good')
elseif ((Toefl >= 401) && (Toefl <= 500)) && (((Math >= 401) && (Math <= 500)) && ((Bio >= 401) && (Bio <= 500)))
disp ('Average')
else (((Toefl <= 400)) && ((Math <= 400)) && ((Bio <= 400)));
disp ('bad')
end
how can i fix it?
the asked result maybe like this
>> Untitled4
Toefl=602
Toefl =
602
Mathematic=502
Math =
502
Biologi=402
Bio =
402
Toefl Excellent
Mathematic Good
Bio Bad
>>
my lecturer said that forbidden to use loops. Thanks
Answers (1)
Raj
on 11 Apr 2019
Edited: madhan ravi
on 11 Apr 2019
Try this:
Toefl=input('Toefl=')
Math=input('Mathematic=')
Bio=input('Biologi=')
if((Toefl >= 601) && (Toefl <= 670)) && ((Math >= 601) && (Math <= 670)) && ((Bio >= 601) && (Bio <= 670))
disp ('Excellent')
elseif ((Toefl >= 501) && (Toefl <= 600)) && (((Math >= 501) && (Math <= 600)) && ((Bio >= 501) && (Bio <= 600)))
disp ('Good')
elseif ((Toefl >= 401) && (Toefl <= 500)) && (((Math >= 401) && (Math <= 500)) && ((Bio >= 401) && (Bio <= 500)))
disp ('Average')
elseif (((Toefl <= 400)) && ((Math <= 400)) && ((Bio <= 400)));
disp ('bad')
else
disp ('Invalid Data')
end
7 Comments
Noah Jacob
on 11 Apr 2019
Raj
on 11 Apr 2019
Hi,
Sorry your question was not so clear earlier. I thought you just wanted to "fix" the code.
If you want result displayed for each subject separately without using any loop then why don't you split the if-else conditions for each subject like this:
if((Toefl >= 601) && (Toefl <= 670))
disp ('Toefl:Excellent')
elseif ((Toefl >= 501) && (Toefl <= 600))
disp ('Toefl:Good')
elseif ((Toefl >= 401) && (Toefl <= 500))
disp ('Toefl:Average')
elseif (((Toefl <= 400))
disp ('Toefl:bad')
else
disp ('Toefl:Invalid Data')
end
Repeat the same for Math and Bio.
madhan ravi
on 11 Apr 2019
@Raj: You can select the code and press the code button so that it’s easy to read.
Raj
on 11 Apr 2019
Oh right right....sorry i missed that.will take care in future. Thanks :)
Noah Jacob
on 11 Apr 2019
Raj
on 11 Apr 2019
I am not sure what exactly you are looking for. I thought only use of "for" loop is forbidden.
Noah Jacob
on 11 Apr 2019
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!