-
January 10th, 2014, 11:14 AM
#1
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, 11:46 AM
#2
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!
Victor Nijegorodov
-
January 10th, 2014, 11:48 AM
#3
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!
Victor Nijegorodov
-
January 10th, 2014, 01:00 PM
#4
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, 01:10 PM
#5
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, 01:30 PM
#6
Re: problem with if and else if
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, 01:32 PM
#7
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, 01:41 PM
#8
Re: problem with if and else if
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, 01:56 PM
#9
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, 09:40 AM
#10
Re: problem with if and else if
it's solved thanks for your help
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|