Drink machine

Hi guys & girls.

ive read up on structures initialization but I have no idea if im doing it right or wrong.

Im creating an soft drink simulation, and I have to use structures, it should store an array of five structures and initialized with the data given

Drink Name Cost Number in Machine
(in pence)
Cola 0.75 20
Beer 0.75 20
Lemon-Lime 0.75 20
Grape Soda 0.80 20
Cream Soda 0.80 20

I have created the structure -

1
2
3
4
5
6
struct DrinkMachine
{
	string name; //name for drinks
	double cost; //cost of drinks
	int num; // number of drinks inside machine
};

however Im not sure how you initialize it through the structures array, any help would be great.

Thanks!
Last edited on
1
2
3
4
5
6
      struct DrinkMachine struct_arr[5];
         strcpy(struct_arr[0].name,"cola");
         struct_arr[0].cost=100;
         struct_arr[0].num=11;

 

try the above code
Last edited on
Might be something like

1
2
3
4
5
6
7
8
9
10
11
12
13

// when I = the array index

drinkarray[I].name = (what you want);

drinkarray[I].cost = (what you want);

drinkarray[I].num = (what you want);

// you could also use cin for input if you need to do that

cin >> drinkarray[I].cost;


Just think of drinkarray[i] as the actual name of the struct variable in the specified array slot.

please make as solved if satisfied as this helps people help you.
Last edited on
Topic archived. No new replies allowed.