works, allows entering a user selected amount of strings, however when i try to display, it displays only the last string, not the whole 'database', whatever you'd call it :)
the main question is what is wrong and also, is there any way to not to ask a user to enter a number? maybe theres a way to auto expand the strings?
#include <iostream>
#include <string>
using namespace std;
class list
{
public:
int iMemberCount;
string *sName;
string *sAge;
void task();
void newInfo();
void preview();
void memCount(int iTotalMemb);
list();
};
//========================================================
list::list()
{ iMemberCount=0; }
//========================================================
void list::memCount(int iTotalMemb)
{ sName=new string[iTotalMemb];
sAge=new string[iTotalMemb];
iMemberCount = iTotalMemb; }
//========================================================
void list::task()
{ cout<< "1. new profile \n";
cout<< "2. preview \n";
int iChoice; cin>> iChoice;
switch(iChoice)
{ case 1: newInfo(); break;
case 2: preview(); break; }
}
//========================================================
void list::newInfo()
{ cout<< "name- "; cin>> *sName;
cout<< "age- "; cin>> *sAge;
cout<< endl; }
//========================================================
void list::preview() //these lines are responsible for display
{ for (int i=0; i<iMemberCount; i++)
cout<< sName[i] << " " << sAge[i]; }
//========================================================
int main()
{
list people;
int iChc;
cout<< "max number of people in the list- ";
cin>> iChc; //user must enter a number, any way to avoid this?
people.memCount(iChc);
for (;;)
{ int index=0; index++;
people.task();
if (index==iChc) break;
}
return 0;
}