Thread: newbie-functions??

  1. #1
    Unregistered
    Guest

    Question newbie-functions??

    Hi,
    i am stuck on how to take the return value from one funcn and use it in other 2 funcns.
    in this case, i am getting return value from calctottime ,and wants to use it in calcmins and calcsecs.

    thanks.....


    Code:
    int main()
    {
    ....
    cout<<"the total time is"<<calctottime( t1,t2,t3);
    calcmins(totT);
     calcsecs(totTa);
    return 0;
    }
    
    int calctottime(int time,int time1 ,int time2)
    {
    ........
    totalTime=time+time1+time2;
    		
    return totalTime;
    
    }
    
    void calcmins(int totTime)
    {
    cout<<"the mins r"<<totTime/60<<endl;
    }
    
    void calcsecs(int totTimes)
    {
    
     cout<<"the seconds r"<<totTimes%60<<endl;
    }

  2. #2
    Unregistered
    Guest

    Lightbulb no reply???HELLLPPPP

    Hi,
    10 reads in 5 mins, and not a single reply!!!please help me out.....
    thanks

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Re: newbie-functions??

    Originally posted by Unregistered
    Hi,
    i am stuck on how to take the return value from one funcn and use it in other 2 funcns.
    in this case, i am getting return value from calctottime ,and wants to use it in calcmins and calcsecs.

    thanks.....


    Code:
    int main()
    {
    ....
    cout<<"the total time is"<<calctottime( t1,t2,t3);
    calcmins(totT);
     calcsecs(totTa);
    return 0;
    }
    
    int calctottime(int time,int time1 ,int time2)
    {
    ........
    totalTime=time+time1+time2;
    		
    return totalTime;
    
    }
    
    void calcmins(int totTime)
    {
    cout<<"the mins r"<<totTime/60<<endl;
    }
    
    void calcsecs(int totTimes)
    {
    
     cout<<"the seconds r"<<totTimes%60<<endl;
    }
    You must either assign the function calls to a variable or compare them to other values.


    Example:

    unsigned int fMins = calcmins(totT);
    unsigned int fSecs = fSecscalcsecs(totTa);

    or

    if (calcmins(totT) == fSecsCalcsecs(totTa))
    {
    doSomething();
    }

  4. #4
    The best way and the recommended way of achieving this is to put your returned values into variables.

    //if calctotime() returns an int, just place the value in an int variable that is global or static, Class encalpulation is the best, and that way you can pass the value to other functions.

    int c_to_time = calctotime(t1,t2,t3);

    and so on for your other functions that return values.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    23

    Re: no reply???HELLLPPPP

    Originally posted by Unregistered
    Hi,
    10 reads in 5 mins, and not a single reply!!!please help me out.....
    thanks
    um why not store the returned answer from calctotime into a variable and reuse it?

    such as:

    int foo = calctottime( t1,t2,t3);

    then calling the function with the variable:

    calcmins(foo);
    calcsecs(foo);

    Hope that helps..

    -Dennis

  6. #6
    Unregistered
    Guest

    Smile thanks a heap

    thanks a lot .....u made my day!!!
    may god bless u!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. Memory handling functions (newbie questions)
    By PaulBlay in forum C Programming
    Replies: 6
    Last Post: 03-10-2009, 06:37 AM
  3. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Newbie asking about overloading functions
    By GLR in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2001, 10:54 AM