Returning a value from a function

This is a discussion on Returning a value from a function within the C++ Programming forums, part of the General Programming Boards category; hi there, i tried to return a value from a function and the value returned will be used another function. ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    18

    Returning a value from a function

    hi there, i tried to return a value from a function and the value returned will be used another function. here is my code
    Code:
    void processL()
    {
    	.....
    	.....
    	if(nameLine==Name && passLine==Password)
    	{
    		valid = false;
    		return valid
    	}
    }
    Code:
    void processA()
    {
    	.....
    	.....
    	check = customerLogin();
            if(check == true)
    	  {
    	      cout<<"success";
    	  }
    	else
    	   cout<<"Failed";
              
    }
    i meant to use the value returned on processA(), but i'm unable to do it. can u give some help or advice ??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    err... what value are you returning, and why do you declare the return value as void if you want to return something?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Code:
    void processL()
    {
    	.....
    	.....
    	if(nameLine==Name && passLine==Password)
    	{
    		valid = false;
    		return valid
    	}
    // and what value are you returning if you get here?
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    A void function cannot return a value...it has to be an int function or float etc. Do you not also need to pass parameters?

    Edited out: Why, if you are using the value returned from processA in processL is there no value returned in A?

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Code:
    int processL(int valid)
    {
    	int completeandutterloser = -1;
            .....
    	.....
    	if(nameLine==Name && passLine==Password)
    	{
    		valid = false;
    		return valid
    	}
            return completeandutterloser; 
    }
    Code:
    void processA(int valid)
    {
    	.....
    	.....
    	check = customerLogin();
            if(check == true)
    	  {
    	      cout<<"success";
    	  }
    	else
    	   cout<<"Failed";
              
    }

    I could be wrong as that might not do what you want it to (feedback if I am right please) If valid is not a parameter of processL then you have to define it in processL.....I think!

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    You would want to return a bool, not int, since the code uses true and false. And there is no need for a parameter here.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Woops

    Apart from that was I right?


    Edit: I had a dumb and dumberndumberer moment there for some reason I was thinking false was a variable and valid was now equal to that!

    /me shoots homself in the foot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 03:30 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. returning pointers from a function
    By curlious in forum C++ Programming
    Replies: 2
    Last Post: 12-28-2003, 10:37 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21