I need a bit of help as I have just started learning c++
Currently, I have this.
#include "stdafx.h"
#include <iostream>
int main()
{
using namespace std;
struct CandyBar
{
char brand[20];
double weight;
int calories;
};
CandyBar *pt = new CandyBar [3];
pt = &pt[0];
*pt = { "Nestle", 2.5, 632 };
cout << "Brand: " << pt->brand << endl << "Weight: " << pt->weight << endl << "Calories: " << pt->calories << endl;
pt = &pt[1];
*pt = { "Nestle", 2.5, 632 };
cout << "Brand: " << pt->brand << endl << "Weight: " << pt->weight << endl << "Calories: " << pt->calories << endl;
pt = &pt[2];
*pt = { "Nestle", 2.5, 632 };
cout << "Brand: " << pt->brand << endl << "Weight: " << pt->weight << endl << "Calories: " << pt->calories << endl;
delete [] pt;
cin.get();
return 0;
}
Unfortunately, it isn't seem to be working and I am not sure if what I am doing is correct either.
It would be great if someone would help.
Cheers.


Sign In
Create Account


Back to top










