When I run this code, I get the prompt asking if I want to add a new record, I choose 'y', then I get an executable error. Can anyone tell me where the problem is?
Code://struct.h #ifndef _STRUCTUR_H #define _STRUCTUR_H class customerData{ public: // customerData(); private: char firstName[20]; char lastName[20]; char address[50]; char city[50]; char state[50]; int zip; int account; int pin; public: customerData* listArray [5]; void addRecord(); void displayRecord (int, customerData mlRec, customerData rec); }; void customerData::addRecord() { int index = 0; customerData& rec = *listArray[index]; for (int i=0; i<5; i++) listArray [i] = new customerData; cout << "First name: "; cin.getline (rec.firstName, sizeof(rec.firstName) -1); cout << "Last name: "; cin.getline (rec.lastName, sizeof (rec.lastName) -1); cout << "Address: "; cin.getline(rec.address, sizeof (rec.address) -1); cout << "City: "; cin.getline (rec.city, sizeof (rec.city)-1); cout << "State: "; cin.getline (rec.state, sizeof (rec.state)-1); char buff [10]; char buff2[10]; char buff3[10]; cout << "Zip code: "; cin.getline ( buff, sizeof(buff) -1); rec.zip=atoi(buff); cout << "Account number: "; //cin>>rec.account; cin.getline(buff2, sizeof(buff2) -1); rec.account=atoi(buff2); cout << "PIN number: "; //cin>>rec.pin; cin.getline(buff3, sizeof(buff3) -1); rec.pin=atoi(buff3); index++; cout << endl; } void customerData::displayRecord (int num, customerData mlRec, customerData rec) { for (int i=0; i<sizeof listArray[i]; i++) rec.displayRecord (i, *listArray[i], rec); cout << "Record " << (num + 1) << " : " << endl; cout << "Name: " << mlRec.firstName << " " ; cout << mlRec.lastName; cout << endl; cout << "Address: "<< mlRec.address << " " ; cout << endl << " " ; cout << mlRec.city << " , " << mlRec.state << " " << mlRec.zip << endl; cout << "Account: "<< mlRec.account << endl; cout << "PIN: " << mlRec.pin << endl; } #endif //struct.cpp #include <iostream.h> #include <conio.h> #include <stdlib.h> #include "structur.h" int main (int, char**) { customerData data; char response; cout << "Do you want to add a customer, y/n? " ; cin>>response; if (response == 'y'){ data.addRecord(); } else{} return 0; }



LinkBack URL
About LinkBacks


