Hi guys, I'm new and self teaching myself C++. A problem from the book says to create the CandyBar Struct and the create a dynamic array that hold 3 structures, initialize the structures and output each of them. The code works BUT I'm wondering if there is an easier way to initialize each variable or am i stuck with the "sn[0].brandName = ..." way to initialize everything?
struct CandyBar
{
string brandName;
float weight;
int calories;
};
CandyBar* sn = new CandyBar [3];
sn[0].brandName = "snickers";
sn[0].weight = 2.2;
sn[0].calories = 147;
cout << sn[0].brandName << sn[0].weight << sn[0].calories << "\n";
// cout << sn[1].brandName << sn[1].weight << sn[1].calories << "\n";
// cout << sn[2].brandName << sn[2].weight << sn[2].calories << "\n";
delete [] sn;