How to define 2 values for 1 variable.

For example, I want to define product_code with 2 different values: product_name and product_price?
Last edited on
Easiest way is to use a struct.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct product{
        string name;
        double price;
} myProduct;
 
int main()
{
        myProduct.name="Movie";
        myProduct.price=19.99;
 
        cout<<myProduct.name<<" "<<myProduct.price<<endl;
 
        cout<<"Change the values pls"<<endl;
        getline(cin,myProduct.name);
        cin>>myProduct.price;
 
        cout<<myProduct.name<<" "<<myProduct.price<<endl;
 
 
 
}
Topic archived. No new replies allowed.