A little project with big hopes, pls help!

So I am doing my best to learn as much as I can about c++ and since I learned PASCAL in high school, it wasnt that difficult but I always run into some small problems, glitches and stuff, but it finally worked as for now.
Now the first problem I cant seem to solve is how to create the structure of my agenda with "new" and delete it right after with "delete[]"
This is the code so far, and I have big plans with it, but first of all I want to be able to create and delete it whenever I start it.

#include <iostream>
#include <string>
#include <new>
using namespace std;
#define nl cout <<endl;
struct adresa {
string str;
char nr[5];
char bl[5];
char sc[5];
char et[5];
char ap[5];
};
struct agenda {
char NrCrt[2];
string nume;
string prenume;
char NrTel[10];
adresa adr;
};
typedef agenda agd[100];
void creare (agd& a, int n) {
int i;
for (i=0;i<n;i++) {
cout <<"Nr Crt: ";
cin >> a[i].NrCrt;
nl;
cin.ignore();
cout <<"Nume: ";
getline(cin, a[i].nume);
nl;
cout <<"Prenume: ";
getline(cin, a[i].prenume);
nl;
cout <<"Nr Tel: ";
cin >>a[i].NrTel;
nl;
cin.ignore();
cout <<"Strada: ";
getline(cin, a[i].adr.str);
nl;
cout <<"Nr: ";
cin >>a[i].adr.nr;
nl;
cout <<"Bloc: ";
cin >>a[i].adr.bl;
nl;
cout <<"Scara: ";
cin >>a[i].adr.sc;
nl;
cout <<"Etaj: ";
cin >>a[i].adr.et;
nl;
cout <<"Apartament: ";
cin >>a[i].adr.ap;
nl;
}
}
void afisare (agd a, int n) {
int i;
for (i=0;i<n;i++) {
cout <<"Nr Crt: "<<a[i].NrCrt<<endl;
cout <<"Nume: "<<a[i].nume<<endl;
cout <<"Prenume: "<<a[i].prenume<<endl;
cout <<"Nr Tel: "<<a[i].NrTel<<endl;
cout <<"**Adresa**"<<endl;
cout <<"Strada "<<a[i].adr.str<<", Nr "<<a[i].adr.nr<<", Bloc "<<a[i].adr.bl;
cout <<", Scara "<<a[i].adr.sc<<", Etaj "<<a[i].adr.et<<", Ap "<<a[i].adr.ap<<endl;
cout <<"___________________________________________________________";
nl;
}
}

int main () {
int i,n;
agd a;
cout <<"Dati nr de persoane care doriti sa il introduceti in agenda: ";
cin >>n;
if (a==0) cout <<"Error allocating memory, try again with a smaller number!";
else {
creare(a,n);
afisare(a,n);
}
system("pause");
return 0;
}


So far I have tried to do something like this
agenda *a=new (nothrow)agenda[n];
but then I run into other problems like it gives me some errors like it is not right declarer into functions(tho i changed to "void creare(agenda a, int n)...")
still wont work :( or if it works, then it gives another error when im calling the function in the main program. What am I doing wrong?:(
Thanks in advance!
Last edited on
Please use the code tags. It makes your code much easier to read.
Maybe...

void creare (agenda *a, int n)

void afisare (agenda *a, int n)

agenda *a=new (nothrow)agenda[n];

Topic archived. No new replies allowed.