how could i simplify this code?
Code:
#include <iostream>
#include <iomanip>
using namespace std;
class person
{
public:
static int total;
person();
string name;
};
int person::total = 0;
person::person()
{
total++;
}
int main()
{
int x;
do
{
if(x==0)
{
cout<<"Gotta create at least one person."<<endl<<endl;
}
cout<<"How many people do you wanna create? ";
cin>>x;
}
while(x == 0);
person people[x];
cout<<"There are currently "<<person::total<<" people."<<endl;
cin.get();cin.get();
x=0;
string newName;
do
{
cout<<"Whose name do you wanna set? ";
cin>>x;
if(x > person::total)
{
cout<<"There is no such person."<<endl;
cin.get();
cout<<endl;
continue;
}
if(x != 0)
{
cout<<endl<<"Enter a name for Person N. "<<x<<": ";
cin>>newName;
people[x].name = newName;
cout<<"Person N. "<<x<<"'s name has been set to "<<newName<<".";
cout<<endl<<endl;
}
}
while(x != 0);
}
also, i'd like to list all the people's names that have been set, but i still havent figured out how to do that.