I am having problems finding infromation on using the &x I know how it is used... I am just wondering about general functions that return more than one parameter, looking for practical examples...

Printable View

- 09-06-2001Unregisteredmore than one return parameter
I am having problems finding infromation on using the &x I know how it is used... I am just wondering about general functions that return more than one parameter, looking for practical examples...

- 09-06-2001lightatdawn
A function can only return one parameter. You could i suppose return a pointer to an array or struct of data though.

- 09-06-2001Unregistered
I mean &x pointers, for instance one example I have is adding, subtracting, and multiplying 2 different numbers, and having the results returned... but I need other practical examples

- 09-06-2001zoo
Here's a simple example.

Code:`#include <iostream>`

using namespace std;

int main()

{

double a, b, s, d, p, q;

cout << "Enter two numbers:";

cin >> a >> b;

calculate(a,b,s,d,p,q);

cout << a << "+" << b << "=" << s << endl;

cout << a << "-" << b << "=" << d << endl;

cout << a << "*" << b << "=" << p << endl;

cout << a << "/" << b << "=" << q << endl;

return 0;

}

void calculate(double a, double b, double &sum, double &dif, double &prod, double ")

{

sum = a + b;

dif = a - b;

prod = a * b;

quot = a / b;

}

- 09-06-2001Unregistered
thanks for example... but that is the one I already have... I was looking for other practical examples...

- 09-06-2001Witch_King
References or else pointers are the best way to go. Use the example, it's very practical. If you have a group of data than create a class and pass it by reference to the caller.