| | |
Function to make a variable equal to other variables
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 32
Reputation:
Solved Threads: 0
very simple question: what is the most easiest way to do the following
I have two variables
a=1;
b=2;
how do I make it that
c= a,b
so that c=12
I dont want to write
because a and b change according to user input.
Thanks, this should be solved fast
I dont really get what I should "search" for otherwise I would search instead of asking. (also the title is probably pretty bad but not sure what to call this
)
Thanks
I have two variables
a=1;
b=2;
how do I make it that
c= a,b
so that c=12
I dont want to write
C++ Syntax (Toggle Plain Text)
c=12;
Thanks, this should be solved fast
I dont really get what I should "search" for otherwise I would search instead of asking. (also the title is probably pretty bad but not sure what to call this
)Thanks
Last edited by salman213; Jun 20th, 2008 at 7:45 pm.
What I posted is also the method used to convert a string of digits to an integer if you don't want to use a standard C or C++ convertion function.
Here's aother way:
Here's aother way:
int c = (a << 3) + (a << 1) + b; Last edited by Ancient Dragon; Jun 20th, 2008 at 8:25 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
What I posted is also the method used to convert a string of digits to an integer if you don't want to use a standard C or C++ convertion function.
Here's aother way:
int c = (a << 3) + (a << 1) + b;
Edit2: Actually... I think I got it.
a << 3 is the same as a * (2 ^ 3)
a >> 3 is the same as a / (2 ^ 3)
Correct me if I'm wrong on this.
Last edited by Alex Edwards; Jun 20th, 2008 at 8:58 pm.
Point made: it's obfuscatory and should only be used in the archaic systems, from whence it came, that lack the appropriate machine commands and/or a supporting assembly code library.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
Well, you are given two ways of doing the same thing:
One of them is straight-forward, one is not. The one that is not is "obfuscatory" (i.e. more complicated and harder to understand for no reason other than to add confusion).
You're missing the point. When AD posted this:
his point was along the lines of "I've given you a perfectly good solution, yet you ask for another one with no explanation of why the first solution doesn't meet your needs." Then he gave you a solution that does the exact same thing as the first solution, but in an overly-complicated way that no one would ever use instead of the first solution. Why don't you like this?
I can't think of a command that will do this any better.
Why are you asking for a different way then? I'm sure we could come up with even more confusing mathematical formulas that do the exact same thing, but that's probably not what you are looking for.
C++ Syntax (Toggle Plain Text)
int c = (a * 10) + b; int c = (a << 3) + (a << 1) + b;
One of them is straight-forward, one is not. The one that is not is "obfuscatory" (i.e. more complicated and harder to understand for no reason other than to add confusion).
•
•
•
•
Is there a specific command that has not been mentioned yet which is now available that will do the same thing?
C++ Syntax (Toggle Plain Text)
int c = (a << 3) + (a << 1) + b;
his point was along the lines of "I've given you a perfectly good solution, yet you ask for another one with no explanation of why the first solution doesn't meet your needs." Then he gave you a solution that does the exact same thing as the first solution, but in an overly-complicated way that no one would ever use instead of the first solution. Why don't you like this?
C++ Syntax (Toggle Plain Text)
int c = (a * 10) + b;
I can't think of a command that will do this any better.
Why are you asking for a different way then? I'm sure we could come up with even more confusing mathematical formulas that do the exact same thing, but that's probably not what you are looking for.
![]() |
Similar Threads
- Help explain how to write algorithm (Computer Science)
- bank system problem !!!! (C++ programming) (C++)
- only a couple of hours to go... (C++)
- Sorting in date order (Visual Basic 4 / 5 / 6)
- Pointers (C++)
- AnsiString Template Data Return Problem Builder 6 (C++)
- Pointers (Part II) (C)
- Data Abstraction (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: how to read data from textfile and push in array
- Next Thread: inheritance with input command
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets







so dumb..lol