0

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;
3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Darth Vader
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.