How to return multiple value from function to main?

Get user input should be done in a function. The function should read the product number, price per unit, and quantity sold and return them to the main().
Display the value of product number, price per unit and quantyty sold in main().
Create a data structure and return an instance of it.
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

struct product
{
int number,quantity;
double price;
};

void getInfo(product info);

int main()
{
getInfo(info);
cout<<"DATA:"<<endl;
cout<<info.number<<info.price<<info.quantity;
return 0;
}

void getInfo(product info)
{
cout<<"Please enter number:";
cin>>info.number;
cout<<"Please enter price:";
cin>>info.price;
cout<<"Please enter quantity:";
cin>>info.quantity;
}

my code got any error?i cant display product info in main()
You passed in info into getInfo() without making it yet.

Declare it, initialize, then use it.

i cant solve it T.T
hint

1
2
3
4
5
6
7
int main()
{
getInfo(info); // what's info? Main doesn't know what that is
cout<<"DATA:"<<endl; 
cout<<info.number<<info.price<<info.quantity;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

struct product
{
int number,quantity;
double price;
};

void getInfo(product info);//In function prototype, you don't need to specify
//variable identifiers.

int main()
{
getInfo(info);
cout<<"DATA:"<<endl;
cout<<info.number<<info.price<<info.quantity;
return 0;
}

//You can obtain the value of this modified object(info) in
//several ways.
//Pass argument by reference(assuming you know what a reference is)
//Return the instance of product.
void getInfo(product info)
{
cout<<"Please enter number:";
cin>>info.number;
cout<<"Please enter price:";
cin>>info.price;
cout<<"Please enter quantity:";
cin>>info.quantity;
}
//If you choose to return the instance of object,
//then simply object = getInfo(object).
//The reason why this works is because every structure
//comes with a predefined "copy constructor",
//which overloads the assignment operator('=').
//What it does is simply to copy every member's value of the 
//right side of the expression, and copy them over to respective
//left side members.

//Personally though, i would have prefered to pass the object as reference in this case.
//If you don't know about references, look it up. 
Solved it. Many Thanks!!
Topic archived. No new replies allowed.