Using switch to determine the AccountCurrency() ?

 

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

double USDBalance;
switch (AccountCurrency())
   {
      case "USD": USDBalance = AccountBalance(); break;
      case "GBP": USDBalance = AccountBalance() * iClose("GBPUSD",0,0); break;
      case "EUR": USDBalance = AccountBalance() * iClose("EURUSD",0,0); break;
      default: Print ("Error in currency determination.");
   }

Can switch handle strings? If not I can always go back to if/else if/else statements...

 
eempc:

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

Can switch handle strings? If not I can always go back to if/else if/else statements...

MQL4 Reference / Language Basics / Operators / Switch Operator

Switch Operator

Compares the expression value with constants in all the case variants and passes control to the operator that corresponds to the expression value. Each variant of case can be marked with an integer constant, a literal constant or a constant expression. The constant expression can't contain variables or function calls. Expression of the switch operator must be of integer type.

 
Oh well...
 
eempc:

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

Can switch handle strings? If not I can always go back to if/else if/else statements...

Convert to ASCII char, then you can use switch, but using nested ifs -= alot of if within if - will do the trick.


Reason: