| | |
Function return question?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 92
Reputation:
Solved Threads: 0
Say you have a class called example:
and you use this to get numbers from the user:
and then you call one function to manipulate the numbers and another to do some more manipulation. How do you get those numbers from one function to the other?
C++ Syntax (Toggle Plain Text)
class example { int one; int two; };
and you use this to get numbers from the user:
C++ Syntax (Toggle Plain Text)
example number; cout<<"enter numbers"<<endl; cin>>number.one>>number.two;
and then you call one function to manipulate the numbers and another to do some more manipulation. How do you get those numbers from one function to the other?
C++ Syntax (Toggle Plain Text)
function1(number.one, number.two); function2(number.one, number.two);
Here is one way it could be done.
C++ Syntax (Toggle Plain Text)
class example { public: int one; int two; }; int function1(int one, int two) { return one * two; } int function2(int one, int two) { return one + two; } int main() { example number; cout<<"enter numbers"<<endl; cin>>number.one>>number.two; cout << function1( function2(number.one, number.two), 3); }
Last edited by Ancient Dragon; Oct 12th, 2008 at 8:01 pm.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
You can do it any way you want. You don't even have to nest the two functions like I showed you.
There are lots of ways to do what you described. Let your imagenation be your guide and try them out with your compiler to see what happens. Practice makes perfect
C++ Syntax (Toggle Plain Text)
int n = function2(number.one, number.two); cout << function1( n, number.two);
There are lots of ways to do what you described. Let your imagenation be your guide and try them out with your compiler to see what happens. Practice makes perfect
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
![]() |
Similar Threads
- Javascript Function return value into PHP or not ?? Please help !! (JavaScript / DHTML / AJAX)
- Function templates question (C++)
- just a quick question (C++)
Other Threads in the C++ Forum
- Previous Thread: Reading text file and copying to new one. Bit file editing too.
- Next Thread: Help with a function
Views: 403 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






