Variable for + - * /

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 58
Reputation: Darth Vader is an unknown quantity at this point 
Solved Threads: 0
Darth Vader Darth Vader is offline Offline
Junior Poster in Training

Variable for + - * /

 
0
  #1
Oct 25th, 2009
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 Variable Number2;
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster
 
0
  #2
Oct 25th, 2009
Well is it that you want the value of the variable to be changed at run-time or during compilation.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: stonerain is an unknown quantity at this point 
Solved Threads: 2
stonerain stonerain is offline Offline
Newbie Poster
 
0
  #3
Oct 25th, 2009
That's not possible actually but you can use the switch-case structure for this operation.
A.K.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: Darth Vader is an unknown quantity at this point 
Solved Threads: 0
Darth Vader Darth Vader is offline Offline
Junior Poster in Training
 
0
  #4
Oct 25th, 2009
The variable should be changed during runtime of the code.

Originally Posted by Sky Diploma View Post
Well is it that you want the value of the variable to be changed at run-time or during compilation.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: Darth Vader is an unknown quantity at this point 
Solved Threads: 0
Darth Vader Darth Vader is offline Offline
Junior Poster in Training
 
0
  #5
Oct 25th, 2009
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.

  1. String^ Operator = "Mult";
  2. double Number1 = 5;
  3. double Number2 = 10;
  4. double NewNumber = 0;
  5.  
  6. if( Operator == "Mult" )
  7. {
  8. NewNumber = Number1 * Number2;
  9. }
  10. else
  11. {
  12. NewNumber = Number1 - Number2;
  13. }

Originally Posted by stonerain View Post
That's not possible actually but you can use the switch-case structure for this operation.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC