How to return 2 result from a funtion

I wonder how to get two result from a function.Can someone be kind to help me .Thank you in advance.
I am a beginner as well so I may be wrong, but I don't think it is possible to get more than one return value from a function. If you need more and can't avoid it otherwise, you could define the variables you need globally.
Short answer: You can't

Slightly longer answer: You can make a structure to hold several data values, and return that.

There are a few ways. One is to create a struct to contain your two values:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct score
{
    int goals;
    int rank;
};

score get_score(const player& p)
{
    score s;

    // ... calculate score total goals and rank

    return s;
}

Another is to pass in parameters by reference:
1
2
3
4
void calc_game(const player& p; int& goals, int& rank)
{
    // set goals and rank here
}

Passing by reference means that the values will be 'passed back' to the caller if the function changes them.
Excellent!! Thank you so much.
Topic archived. No new replies allowed.