How do I say if grade equals 69 or 79 or 89 etc. I tried using the or symbol but that didnt work (it made the sign a + for every input no matter what). Is there away to do this other than writing out :
if (grade == 69)||(grade==79||(grade==89) etc. etc.
?
here is my actual code:
1 2 3 4 5
if (grade == 69,79,89,99,68,78,88,99,100)
{
sign ='+';
}
Thanks for the answer. I didn't see that on the other thread. But this isnt a duplicate, I decided to do it a different way by listing them all out where as before I was trying to make a .at statement do it for me. Thanks.
Also if I did want to list a bunch of numbers like I stated above how would I do it?
Would I have to write them all out like if (grade == 69)||(grade==79||(grade==89) etc. etc.?
I understand order of operations I just don't understand why an input for score of say 85 would return true. I understand why it returns true for those values(69,79,89etc.), but I don't understand why it returns true for every value of score.
Sorry if I am kind new to this stuff. You have been very patient with me and I appreciate your help.
Basically, each side of a logical operator is a complete statement. So if you say:
if(score == 69||79)
Then you're saying 'if score equals 69 or if 79 exists'.
However, if you were to say:
if(score == 69 || score == 79)
Then you're putting a complete statement on both sides of the operator, and it will read as 'if score equals 69 or if score equals 79'.
Also remember: true is defined as not zero. So we could also put it like this: if(score == 69 || 79)
and score is 85 so if(85 == 69 || 79)
we do the == first (order of operations) if(false || 79)
and true is anything that is not zero, so 79 is true: if(false || true)
false || true is true if(true)
So basically anything I line of in those or statements that isnt a zero will get marked as true. So the whole statement will be true as long as one item in the or statement isn't 0.
Thanks guys this helped!