im having some trouble with this code im learning from. Maby some one can help. I mean i understand it all but i cant figure out what is wrong
anyways here it is:
#include "stdafx.h"
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include "STRUCTUR.h"
void displayRecord(int, mailingListRecord mlRec);
int main(int argc, char* argv[])
{
//
// create an array of mailingListRecord structures
//
mailingListRecord listArray[3];
cout << endl;
int index = 0;
//
// get three records
//
do {
cout << "First Name: ";
cin.getline(listArray[index].firstName,
sizeof(listArray[index].firstName)-1);
cout << "Last Name: ";
cin.getline(listArray[index].lastName,
sizeof(listArray[index].lastName)-1);
cout << "Adress: ";
cin.getline(listArray[index].address,
sizeof(listArray[index].address)-1);
cout << "City: ";
cin.getline(listArray[index].city,
sizeof(listArray[index].city)-1);
cout << "State: ";
cin.getline(listArray[index].state,
sizeof(listArray[index].state)-1);
char buff[10];
cout << "Zip: ";
cin.getline(buff, sizeof(buff)-1);
listArray[index].zip = atoi(buff);
index++;
cout << endl;
} while (index<3);
//
// clear the screen
//
clrscr();
//
// display the three records
//
for (int i=0;i<3;i++) {
displayRecord(i, listArray[i]);
}
//
// ask the user to choose a record
//
cout << "Choose a Record: ";
char rec;
//
// be sure only 1,2 or 3 was selected
//
do {
rec = getch();
rec -= 49;
} while (rec < 0 || rec > 2);
//
// assign the selected record to a temporary variable
//
mailingListRecord temp = listArray[rec];
clrscr();
cout << endl;
//
// display selected record
//
displayRecord(rec, temp);
cout << endl;
return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
cout << "Record " << num + 1 << ":" << endl;
cout << "Name: " << mlRec.firstName << " ";
cout << mlRec.lastName;
cout << endl;
cout << "Adress: " << mlRec.address;
cout << " ";
cout << mlRec.city << ", ";
cout << mlRec.state << " ";
cout << mlRec.zip;
cout << endl << endl;
}
and here is the header;
#ifndef _STRUCTUR_H
#define _STRUCTUR_H
struct mailingListRecord {
char firstName[20];
char lastName[20];
char address[50];
char city[20];
char state[20];
int zip;
};
#endif
its weird everything seems to check out