Jump to content
• ### What is your GameDev Story?

• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Quick Question -- Howdo i get a function to return multiple values

This topic is 5890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

(C++)

int GenerateRandomOblio ( int a , int b , int c , int d )
{
srand ( time( 0 ) );

do
{
a = rand() % 9 + 1;
b = rand() % 9 + 1;
c = rand() % 9 + 1;
d = rand() % 9 + 1;
}
while( a != b && a != c && a != d && b != c && b != d && c != d );

return (a , b , c , d);
}

When i run this program and cout the value, it displays only a. (What i am trying to do is return four integers != to one another) Any help would be appreciated. thanks [edited by - MrPoopypants on December 6, 2002 8:20:03 PM]

#### Share this post

##### Share on other sites
Advertisement
You can only return one value from a function.

However, you can return a pointer to something. IE -- a pointer a to a structure.

Also, you can pass those integers as pointers to the function and then you can modify those so that when you return from the function, a, b, c, and d are modified to reflect what you did with them in the function (I think this is what you want to do).

[edited by - randomDecay on December 6, 2002 8:21:37 PM]

#### Share this post

##### Share on other sites

  struct ret_value{int a,b,c,d;};ret_value myfunc(){...}orpair<pair<int,int>,pair<int,int> > myfunc(){return make_pair(make_pair(a,b),make_pair(c,d));}or even better, check out boost::tuple

edit: code vs source tags

[edited by - sjelkjd on December 6, 2002 8:34:15 PM]

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 9
• 9
• 9
• 34
• 16
• Advertisement
• ### Forum Statistics

• Total Topics
634123
• Total Posts
3015654
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!