Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to do if condition with && operator in c++

What I have tried:

if else condition with && i cant do it
Posted
Updated 8-Aug-16 0:21am

 
Share this answer
 
v2
Comments
Maciej Los 10-Aug-16 16:03pm    
5ed!
Patrice T 10-Aug-16 16:05pm    
Thank you.
Try:
C++
if (a >= b && a <= c)
   {
   DoSomething(1);
   }
else
   {
   DoSomething(2);
   }
 
Share this answer
 
Comments
Member 12675098 8-Aug-16 5:39am    
like if ((a>b)&&(b>c)&&(c>d)) something like that
OriginalGriff 8-Aug-16 5:41am    
Yes.
Member 12675098 8-Aug-16 5:46am    
how?
im having trouble about the
if
cout<<
else if
cout<<
else
cout<<

is that right?
OriginalGriff 8-Aug-16 5:52am    
Sorry - you have to remember that we can't see your screen, can't access your HDD, and can't read your mind! We only get exactly what you type to work from, so when you type a short piece of incomplete code we have no context to read it in and it's completely meaningless without that.
So stop, back up a bit and try explaining your problem in words, rather than shorthand. You know what question you are supposed to be answering for your homework, but we don't! :laugh:
Patrice T 8-Aug-16 6:23am    
Use Improve question to update your question.
The && operator cannot replace the else clause. Instead, it is equivalent to nested if statements, e.g.
C++
if (a > b && a > c)
{
  // do something
}

is equivalent to
C++
if (a > b)
{
  if (a > c)
  {
    // do something
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900