Hi,
Can any one please describe that if we can use || and && operator in C++ as following ?

if (choice == 'e' || 'E' && cur == 'd' || 'D' )
  { cout << " Enter amount in Euro " ;
     cin >> amount ;
    }

We can but not the way you showed it.

if ( (choice == 'e' || choice ==  'E') && (cur == 'd' || cur == 'D' ) ){
 //...
}

You should use a switch statement

char letter;
while (cin>>letter)
  {
    switch (letter)
      {
        case 'd':
        case 'D':
        case 'e':
        case 'E':
         //code here
        break;
       }
   }

You should use a switch statement

char letter;
while (cin>>letter)
  {
    switch (letter)
      {
        case 'd':
        case 'D':
        case 'e':
        case 'E':
         //code here
        break;
       }
   }

There are two different variables in the OP's if statement, your approach will not work.

:) yeah i omitted the "&&"

char letter;
char currency;
while (cin >> letter)
  {    
    switch (letter)
       {
         case 'd':
         case 'D':
           switch (currency)
             {
               case 'E':
               case 'e':
                 // bankruptcy
               break;
             }
        }
   }

anyway :) an if statement would suit better so ignore this

A switch case inside another switch case is strictly a no no. It goes to show that your program is not modular enough. You'll have a hard time maintaining it. Others will have a hard time understanding the logic.

:) yeah i omitted the "&&"

char letter;
char currency;
while (cin >> letter)
  {    
    switch (letter)
       {
         case 'd':
         case 'D':
           switch (currency)
             {
               case 'E':
               case 'e':
                 // bankruptcy
               break;
             }
        }
   }

anyway :) an if statement would suit better so ignore this

We can but not the way you showed it.

if ( (choice == 'e' || choice ==  'E') && (cur == 'd' || cur == 'D' ) ){
 //...
}

Thanks bro :) , that's what I was looking for .course restriction doesn't permit me to use " switch " .thanks again .

Please mark the thread as solved if you feel that you have found your answer here. Happy coding!

This question has already been answered. Start a new discussion instead.