I wonder for something. If it is possible to replace for example * with any kind of variable that holds either: + - * /

Something like:

Variable = *;

double Number1 = 5;
double Number2 = 10;
double NewNumber = 0;

NewNumber = Number1 [B]Variable[/B] Number2;

Recommended Answers

All 4 Replies

Well is it that you want the value of the variable to be changed at run-time or during compilation.

That's not possible actually but you can use the switch-case structure for this operation.

The variable should be changed during runtime of the code.

Well is it that you want the value of the variable to be changed at run-time or during compilation.

Ok, that is not possible ? So the only way to do this is to do any kind of check like this.
Why I wanted to find any kind of variable is that code can be so much shorter if that was possible. This is really to "hard code" everything out.

String^ Operator = "Mult";
double Number1 = 5;
double Number2 = 10;
double NewNumber = 0;

if( Operator == "Mult" )
{
     NewNumber =   Number1 * Number2;
}
else
{
     NewNumber =   Number1 - Number2;
}

That's not possible actually but you can use the switch-case structure for this operation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.