how to make 3 differents inputs with if else statement
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Raj
2019년 4월 11일
편집: madhan ravi
2019년 4월 11일
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
Noah Jacob
2019년 4월 11일
Raj
2019년 4월 11일
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
2019년 4월 11일
@Raj: You can select the code and press the code button so that it’s easy to read.
Raj
2019년 4월 11일
Oh right right....sorry i missed that.will take care in future. Thanks :)
Noah Jacob
2019년 4월 11일
Raj
2019년 4월 11일
I am not sure what exactly you are looking for. I thought only use of "for" loop is forbidden.
Noah Jacob
2019년 4월 11일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!