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??
Re: problem with if and else if
Please, format your code with proper indentations. Example:
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!
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!
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.
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.
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.
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.
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
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.
Re: problem with if and else if
it's solved thanks for your help