Find the answer to your Linux question:
Results 1 to 7 of 7
Dear all I'm writing a C++ program including 2 routines where I need to pass result of one routine to another for further calculations. How to I proceed with it? ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    3

    Passing result of one routine to another

    Dear all

    I'm writing a C++ program including 2 routines where I need to pass result of one routine to another for further calculations. How to I proceed with it? Please help...
    My program1.C is like this -
    Code:
    //program1:
    
    using namespace std;
    
    #include <iostream>
    #include <cstdlib> 
    #include <cmath>
    
    int main ()
    {
    float x1, y1, z1, x2, y2, z2, xa, ya, za, theta, omega;
    
    cout << "\nEnter Pt.1 X value\t";
    cin >> x1;
    cout << "\nEnter Pt.1 Y value\t";
    cin >> y1;
    cout << "\nEnter Pt.1 Z value\t";
    cin >> z1;
    
    cout << "\nEnter Pt. 2 X value\t";
    cin >> x2;
    cout << "\nEnter Pt.2 Y value\t";
    cin >> y2;
    cout << "\nEnter Pt.2 Z value\t";
    cin >> z2;
    
    xa = fabs(xr-xs); ya = fabs(yr-ys); za = fabs(zr-zs);
    theta = atan(za/(sqrt(xa*xa + ya*ya))); 
    omega = atan(ya/xa);
    
    cout << "\ntheta = "<< theta;
    cout << "\nomega = "<< omega;
    cout << "\n\n";
    
    (theta, omega) = program2();  // don't know if this is correct
    }
    Last edited by devils casper; 02-08-2008 at 12:31 PM. Reason: Added [code] .... [/code] tag.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    When does your instructor say this assignment is due?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    3
    This is not an assignment. I'm new to C++ and Unix and trying out to develop a software. Kindly reply if you have a solution.

    Its easier to make fun than to help.

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    functions to a function

    do you mean something like this?

    void func(int&, int&);

    void func2(void (*)(int&, int&), int&, int&);

    where func2 contains func prototype as a parameter.

    or

    int func(int x);

    int func2(int x);

    int y = func2(func(45));

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    wje asked that question because this does sound like a homework assignment, and you gave us no context in which to work. It is against the forum rules to put up homework assignments, hence the question.

    So then, I'm afraid I don't understand what you're trying to do. You have a function called program2, apparently. Are you trying to pass theta and omega into program2? What does program2 do? What parameters does it take?
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    wje asked that question because this does sound like a homework assignment, and you gave us no context in which to work. It is against the forum rules to put up homework assignments, hence the question.
    Precisely.

    Welcome! I hope we can help you. Cabhan has started you out with a question for which I'd like the answer as well. :)
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Feb 2008
    Posts
    3
    Well! Cabhan and wje_lf

    Thanx a lot for the elite advice from you. Your reactions/comments to my query have boosted my confidence in getting enormous help from this forum.

    gerard4143
    I sincerely appreciate a lot your direction. It helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...