Your variables are local to your functions. Your printdata() has variables that are not initialized and contain memory garbage (leftovers from the execution of your getdata() function). No wonder what you see on the screen doesn't make sense. You need the data (the variables) to be accessible for both of your functions.
Since you use C++, your best bet would be to organise your data and functions into a class, so every member of the class can access the same fields (age, name, etc).
One more thing to consider is that you may run out of buffer. 20 characters (19 as you need to reserve one for the terminating zero) may not be enough for the name or city or education. Using std::string would be a better choice.
Here's my code with the above suggested changes.
#include <iostream>
class Person
{
private:
int age;
int id;
std::string name;
std::string city;
std::string education;
public:
void GetData()
{
std::cout << "Enter id of person: ";
std::cin >> id;
std::cout << "Enter name of person: ";
std::cin >> name;
std::cout << "Enter city of person: ";
std::cin >> city;
std::cout << "Enter age of person: ";
std::cin >> age;
std::cout << "Enter education of person: ";
std::cin >> education;
}
void PrintData() const
{
std::cout << "Id of person: " << id << std::endl;
std::cout << "Name of person: " << name << std::endl;
std::cout << "City of person: " << city << std::endl;
std::cout << "Age of person: " << age << std::endl;
std::cout << "Education of person: " << education << std::endl;
}
};
int main()
{
Person person;
person.GetData();
std::cout << std::endl << "The collected data:" << std::endl << "-------------------" << std::endl;
person.PrintData();
return 0;
}