I am confused about it.Thanks a lot.
I am confused about it.Thanks a lot.
What are you having problems with specificly?Code:if ( test_1 is true ) { if ( test_2 is true also ) { do_something( ); } else /* test_2 is not true */ { do_something_else( ); } } else /* test_1 is not true */ { ... more stuff here ... }
Quzah.
Hope is the first step on the road to disappointment.
basically all it is, is an if statement, inside of another if statment, like in the example above.
guns dont kill people, abortion clinics kill people.
if you just have trouble following them and the different outcomes you could draw a little tree like the bad example below
Code:ex: | / \ /\ /\ /\ / \
Originally posted by Draco
if you just have trouble following them and the different outcomes you could draw a little tree like the bad example below
Code:ex: | / \ /\ /\ /\ / \
Does the | mean "IF"?
Originally posted by quzah
What are you having problems with specificly?Code:if ( test_1 is true ) { if ( test_2 is true also ) { do_something( ); } else /* test_2 is not true */ { do_something_else( ); } } else /* test_1 is not true */ { ... more stuff here ... }
Quzah.
if (A) printf("it is A");
{
if (a) printf("it is 1a");
else if(b) printf("it is b");
else if(c) printf("it is c");
else printf("OK");
}
if (B) printf("it is B");
{
if (a) printf("it is 2a");
else if(d) printf("it is d");
else if(e) printf("it is e");
else printf("OK");
}
if (C) printf("it is C");
{
if (a) printf("it is 2a");
else if(d) printf("it is 2d");
else if(f) printf("it is f");
else printf("OK");
}
This is the problem I meet,I am confused about the same IF between A,B,C.Please help me,thank you.
Last edited by shiyu; 02-01-2003 at 02:23 PM.
The first if-statements that trigger the nested sets of statements are capitol letters (A,B,C) while all of the tested letters in the nested statements are lowercase. It would help us if you posted what the upper and lowercase letter are, and any other relevant code.
@shiya
Your code has some additional, unnecessary braces in it. For example:
Should really be written like this:Code:if (A) printf("it is A"); { if (a) printf("it is 1a"); else if (b) printf("it is b"); else if (c) printf("it is c"); else printf("OK"); }
This appears to give a different meaning to the code, albeit only visually.Code:if (A) printf("it is A"); if (a) printf("it is 1a"); else if (b) printf("it is b"); else if (c) printf("it is c"); else printf("OK");
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
These are good responses. Think about it "nested if"
if statements within if statements- also drawing the example out is good as well.
Mr. C: Author and Instructor
if (A) printf("it is A");
if (a) printf("it is 1a");
else if(b) printf("it is b");
else if(c) printf("it is c");
else printf("OK");
if (B) printf("it is B");
if (a) printf("it is 2a");
else if(d) printf("it is d");
else if(e) printf("it is e");
else printf("OK");
if (C) printf("it is C");
if (a) printf("it is 2a");
else if(d) printf("it is 2d");
else if(f) printf("it is f");
else printf("OK");
When I put these three together,It print extra "OK" every time,so how can I make these three work?thank you.
My input are two letters.One is a letter from A,B,C,the other letter is from a-f.
hm... The program may be mistaking the upper and lowercase letters. Instead of just the variables you want to test, try using toupper() on the ones you want to be capital letters and tolower() on the letters that should be lowercase.
>>When I put these three together,It print extra "OK" every time,so how can I make these three work?thank you.
What do you mean by "extra". There are 3 separate if sections that end with an "else", so each of those sections will always print something. Is that where you're getting confused?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]