# problem with if and else if

• January 10th, 2014, 10:14 AM
Faraz95
problem with if and else if
hi.i have several if and else if,but the last if only check one if what's the problem.
plz help
Code:

```if(strcmp(func,"add")==0 || strcmp(func,"ADD")==0) { //some orders. } else { if(strcmp(func,"multiply")==0 || strcmp(func,"MULTIPLY")==0) { //some orders } else { if(strcmp(func,"transpose")==0  || strcmp(func,"TRANSPOSE")==0) { //some orders } else { if(strcmp(func,"sort")==0  || strcmp(func,"SORT")==0) { //some orders } else { if(strcmp(func,"compare")==0  || strcmp(func,"COMPARE")==0) { //some orders } else { cout<<"you have entered wrong answer\n" }}}}}```
but when you entered "sort" ,program sort but print you have entered wrong answer too.
what should i do??
• January 10th, 2014, 10:46 AM
VictorN
Re: problem with if and else if
Code:

```if(strcmp(func,"add") == 0 || strcmp(func,"ADD") == 0) {         //some orders. } else {         if(strcmp(func,"multiply") == 0 || strcmp(func,"MULTIPLY") == 0)         {                 //some orders         }         ... }```
Otherwise it is impossible to understand your logic!
• January 10th, 2014, 10:48 AM
VictorN
Re: problem with if and else if
BTW, what did you mean by "when you entered "sort" ,program sort"?
I don't see any action in the code you have posted!
• January 10th, 2014, 12:00 PM
GCDEF
Re: problem with if and else if
Your question isn't clear, but I would suggest you learn about stricmp. Note the i in the middle.
• January 10th, 2014, 12:10 PM
Faraz95
Re: problem with if and else if
i mean program run well when i entered sort but it also print you have entered wrong answer.
• January 10th, 2014, 12:30 PM
GCDEF
Re: problem with if and else if
Quote:

Originally Posted by Faraz95
i mean program run well when i entered sort but it also print you have entered wrong answer.

The code you posted doesn't do that.
• January 10th, 2014, 12:32 PM
Richard.J
Re: problem with if and else if
Did you run the program in the debugger? That should be pretty straight forward and show you what's going on.
• January 10th, 2014, 12:41 PM
Faraz95
Re: problem with if and else if
Quote:

Originally Posted by Richard.J
Did you run the program in the debugger? That should be pretty straight forward and show you what's going on.

i don't know what debugger is??i use dev compiler
• January 10th, 2014, 12:56 PM
GCDEF
Re: problem with if and else if
Is that your real code? As I said it doesn't do that for me, but it doesn't compile either.
• January 11th, 2014, 08:40 AM
Faraz95
Re: problem with if and else if
it's solved thanks for your help