Hi,
Why the program skip 'read value' in second time? First time reading value is ok, but the problem will get after pressing 'Enter key' for the next time read.
//array of pointers to person objects
#include<iostream.h>
class Person
{
protected:
char name[40];
public:
void getname()
{
cout << "Enter name: ";
cin.getline(name,40,'\n');
}
void putname()
{
cout << "\nName= "<< name;
}
};
void main()
{
Person *persptr[100];
int n=0;
char choice;
do
{
persptr[n] = new Person;
persptr[n]->getname();
n++;
cout << "Enter another(y/n)? ";
cin >> (choice,'\n');
//cout << "\n";
}while(choice=='y');
for(int i=0;i<n;i++)
{
cout << "Person Number: " << i+1;
persptr[i]->putname();
cout << "\n";
}
}
Could anyone please do check for me?
Regards,
zawpai